3 回答
TA貢獻1806條經(jīng)驗 獲得超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);
TA貢獻1818條經(jīng)驗 獲得超8個贊
我相信您需要在頂層處理您想要的數(shù)據(jù)(將新輸入添加到用戶/數(shù)據(jù)庫中的新字段以及所需數(shù)據(jù)等。我不知道您是從哪里得到的userPrincipalName)。
但是,如果不可能,您可以按照以下方式進行操作:
const name = result.userPrincipalName.split('@')[0];
if (!name) throw new Error('Invalid email');
await AsyncStorage.setItem('AZURE-USERNAME', name);
TA貢獻1943條經(jīng)驗 獲得超7個贊
只需您可以split在 Javascript 中使用函數(shù)。更多信息
//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));
添加回答
舉報
