VBScript - 用 2 个目标字符拆分字符串,将它们转换为复合数组,然后从数组中删除不必要的内容
我有一个问题,可能容易,也可能不容易。
我将进一步解释:我有一个像这样的字符串:
str = "TR~Maintenance~fas plus-maintenicon|GR~Supplies~fas minus-suppicon|JK~Affidavit~fas minus-affiicon"
现在,我的目标是将它们分别放入一个数组中,例如:
TR
Maintenance
fas plus-maintenicon
GR
Supplies
fas minus-suppicon
JK
Affidavit
fas minus-affiicon
然后重新整形和重新调整数组以仅保留以 fas 开头的字符串......
什么是最简单的方法吗?分裂?正则表达式?在Str?
我有以下代码:
Function funcSeparaLista(objLst)
arrVLst = split(objLst, "~")
for each x in arrVLst
VLst = VLst&x&"<br/>"
next
funcSeparaLista = split(VLst, "|")
end function
t = funcSeparaLista(str)
但是使用以下方法检索数据:
response.write(t(0))
response.write(t(1))
response.write(t(2))
response.write(t(3))
我得到了不需要的结果:
TR
Maintenance
fas plus-mainteniconGR
Supplies
fas minus-suppiconJK
Affidavit
fas minus-affiicon
最重要的一件事是:我希望我的 FUNCTION 仅处理将分离的字符串放入数组中并在代码的另一部分中处理它。
在数组按照我想要的方式保存所有内容之后,我只希望数组保留这些数据:
fas plus-maintenicon
fas minus-suppicon
fas minus-affiicon
我做错了什么?请记住。这是 vbscript,不是 VB.Net。 提前致谢,我认为这可能非常简单,但在重做和检查代码几个小时后我并没有完全尝试完成它。
I have a question that could be easy or not.
I will explain further: I have a string like this:
str = "TR~Maintenance~fas plus-maintenicon|GR~Supplies~fas minus-suppicon|JK~Affidavit~fas minus-affiicon"
Now, my objective is to put those in an array separately like:
TR
Maintenance
fas plus-maintenicon
GR
Supplies
fas minus-suppicon
JK
Affidavit
fas minus-affiicon
and then reshape and redim the array to keep only, let's say, the strings starting with fas....
What is the easiest method? Spliting? regEx? inStr?
I have the following code:
Function funcSeparaLista(objLst)
arrVLst = split(objLst, "~")
for each x in arrVLst
VLst = VLst&x&"<br/>"
next
funcSeparaLista = split(VLst, "|")
end function
t = funcSeparaLista(str)
But retrieving the data using:
response.write(t(0))
response.write(t(1))
response.write(t(2))
response.write(t(3))
I get undesired results:
TR
Maintenance
fas plus-mainteniconGR
Supplies
fas minus-suppiconJK
Affidavit
fas minus-affiicon
One thing most important: I want my FUNCTION only to deal with putting the detached string in arrays and dealing with it after in another portion of code.
After the array hold everything like I want it, I want only the array to keep this data:
fas plus-maintenicon
fas minus-suppicon
fas minus-affiicon
What I am doing wrong? Remember please. This is vbscript, not VB.Net.
Thanks in advance I think this could be very easy but I am not quite trying to accomplish it after some hours redoing and checking code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个序列化字符串,其中记录分隔符为
|
,字段分隔符为~
。您可以使用双循环轻松构建二维数组。输出:
使用此函数,您可以通过循环并仅返回每行的第三列来获得所需的输出。
输出:
This is a serialised string where the record delimiter is
|
and the field delimiter is~
. You can easily build a 2-Dimensional Array from this using a double loop.Output:
Using this function you can get the output you require by looping through and returning just the 3rd column from each row.
Output: