第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有辦法只將部分字符串對象保存到異步存儲中嗎?

有辦法只將部分字符串對象保存到異步存儲中嗎?

holdtom 2022-10-27 14:41:53
有辦法只將部分字符串對象保存到 async-storage 中嗎?例如,如果在“result.userPrincipalName”中保存“bob23@hotmail.com”,所以我希望它只保存“bob23”,那么該怎么做呢?await AsyncStorage.setItem(          'AZURE-USERNAME',          JSON.stringify(            result.userPrincipalName.substring(0, data.indexOf('@'))          )        );
查看完整描述

3 回答

?
慕森卡

TA貢獻1806條經驗 獲得超8個贊

你公寓這樣的事情。


您可以在某個字符之后刪除部分字符串。


正如我在文檔中看到的那樣。它存儲為鍵值對。


所以我做出了改變


let data = JSON.stringify(result.userPrincipalName);


//here substring will remove characters after and including `@` 

data = data.substring(0, data.indexOf('@'));

await AsyncStorage.setItem('AZURE-USERNAME', data);


查看完整回答
反對 回復 2022-10-27
?
弒天下

TA貢獻1818條經驗 獲得超8個贊

我相信您需要在頂層處理您想要的數據(將新輸入添加到用戶/數據庫中的新字段以及所需數據等。我不知道您是從哪里得到的userPrincipalName)。


但是,如果不可能,您可以按照以下方式進行操作:


const name = result.userPrincipalName.split('@')[0];


if (!name) throw new Error('Invalid email');


await AsyncStorage.setItem('AZURE-USERNAME', name);


查看完整回答
反對 回復 2022-10-27
?
楊__羊羊

TA貢獻1943條經驗 獲得超7個贊

只需您可以split在 Javascript 中使用函數。更多信息

//Split the mame using split function

const splitName = result.userPrincipalName.split("@");


//Get the split value and save it

//After you splitting [0] mean first character set

const name = splitName[0];


//Save it to AsyncStorage

await AsyncStorage.setItem("AZURE-USERNAME", JSON.stringify(name));


查看完整回答
反對 回復 2022-10-27
  • 3 回答
  • 0 關注
  • 113 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號