在VB.NET分割字符串时怪异的结果 [英] Weird results when splitting strings in VB.NET
问题描述
我是越来越怪异的结果对字符串进行多次分裂的时候,所以我决定做一个简单的测试,以找出发生了什么事情。
I was getting weird results when doing multiple splits on a string, so I decided to make a simple test to figure out what was going on
的TestString1234567891011121314151617181920
testString "1234567891011121314151617181920"
如果我在Javascript想10之间获得什么20,我会做这样的:
If I wanted to get whats between 10 to 20 in Javascript I would do this:
var results = testString.split("10")[1].split("20")[0]
这将返回 111213141516171819
不过,我这样做是VB,当我得到的 111
However when I do this in VB I get 111
Split(testString,"10")(1).Split("20")(0)
看来第二拆分只承认第一个字符不管我把。
It seems the 2nd split is only recognizing the first character no matter what I put.
所以它的停止,当它找到下一个2的字符串,甚至2ABC本来,即使该字符串根本不存在相同的结果。
So it's stopping when it finds the next "2" in the string, even "2abc" would have the same outcome even though that string doesn't even exist.
推荐答案
尝试包裹第二分割所以它的塑造像第一个,即:
Try wrapping the second split so it's fashioned like the first one, i.e.:
Split( Split(testString,"10")(1), "20" )(0)"
这篇关于在VB.NET分割字符串时怪异的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!