gpt4 book ai didi

javascript - JS 中第 n 次出现时进行切片/分割

转载 作者:行者123 更新时间:2023-12-02 19:16:27 25 4
gpt4 key购买 nike

我有一个由“|”分隔的字符串组成的数组:

LOG: 380|2|choice|Question_8_13240_1351170102936|||incorrect|2012-10-25T15:01:13|1|<ln>380|2|choice|Question_10_13280_1351170102995|||incorrect|2012-10-25T15:01:17|1| 

并且需要从每个字符串中获取 Question_8_13240_1351170102936 ,以便我可以查看是否有任何重复的问题,即第三次出现“|”之后的字符串4号之前

构建数组的代码:

 AssessmentManager.prototype.submit = function () {
assessData = "";
assessmentItemsLength = this.assessmentItems.length;
for (i = 0; i < this.assessmentItems.length; i++) {
if (!this.assessmentItems[i].getSubmitted()) {
assessmentFlatDataItem = this.assessmentItems[i].getFlatData();
if (assessmentFlatDataItem.length > 0) {
if (assessData.length > 0)
assessData += "<ln>";
assessData += assessmentFlatDataItem;
}
}
}
}

然后获取Flatdata:

  AssessmentItem.prototype.getFlatData = function () {
result = _userScormModuleId + "|";

if (this._interactionIdx)
result += this._interactionIdx;
result += "|";

if (this._interactionType)
result += this._interactionType
result += "|";

if (this._interactionId)
result += this._interactionId
result += "|";

if (this._learnerResponse)
result += this._learnerResponse
result += "|";

if (this._correctResponse)
result += this._correctResponse
result += "|";

if (this._result)
result += this._result
result += "|";

if (this._timeStamp)
result += this._timeStamp
result += "|";

if (this._weighting)
result += this._weighting
result += "|";

if (this._description)
result += this._description

return result;
}

我将如何实现这一目标?谢谢

我现在有这个:

 learnerResponsesArray.push({ 
key: j,
value: this.assessmentItems.split('<ln>')
});

然后循环遍历 learnerResponsesArray?

最佳答案

var cells = mystring.split("|");
// nth item...
var myitem = cells[n];

但正如 @mori57 所说,为什么使用这种格式而不是 JSON?

关于javascript - JS 中第 n 次出现时进行切片/分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13069313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com