我對Google個應用程序腳本很熟悉,每天都在努力學習。我為我的基本知識道歉。我正在嘗試以特定的方式拆分字符串。以下是數組中的字符串:
var data=[呼叫號碼=“7203266298”持續時間=“0”日期=“1646769239639”類型=“2”演示文稿=“1”subscription_id="89148000007344410028“post_dial_digits="”subscription_component_name="com.android.phone/com.android.services.telephony.TelephonyConnectionService“readable_date="Mar 82022 12:53:59 PM”contact_name="(Unknown)"]
現在我想將此文本拆分為以下格式:
var data = [call number="7203266298",
duration="0",
date="1646769239639",
type="2",
presentation="1",
subscription_id="89148000007344410028",
subscription_component_name="com.android.phone/com.android.services.telephony.TelephonyConnectionService",
readable_date="Mar 8, 2022 12:53:59 PM",
contact_name="(Unknown)"]
我嘗試像這樣使用split()
函數:
data = data.split(" ")
但是這個方法的輸出并不是我真正需要的,它創建了不必要的分區,如下所示:
[,call,number=“+12532250046”,duration=“0”,date=“1646851016349”,type=“3”,presentation=“1”,subscription_id="89148000007344410028",post_dial_digits="",subscription_component_name="com.android.phone/com.android.services.telephony.TelephonyConnectionService",readable_date=“2022年3月9日上午11:36:56”,contact_name="(Unknown)",]
任何指導都將不勝感激。
實現這一點的一種方法可以是將數組索引組合到您希望看到的新數組中。例如: