Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
901 views
in Technique[技术] by (71.8m points)

vbscript split string with colon delimiter

I have a project which receives a delimited string through SMS. I am tasked to split the string by colon (:) using the Split function. My SMS server receives the messages and my script processes it.

Sample code:

dim a 
a = split(string,delimiter)
dim value
value = a(1)

Sample input (SMS message): abc:def ghi:jkl

Now when I split it, I was expecting value to return only def, but I get defghi instead. Why?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your output is correct, split() creates an array of substrings which are determined by the delimiter provided.

The substring "def ghi" is due to whitespace being used to separate the characters instead of a colon.

If you don't want the whitespace you can use split again with no given delimiter, " " is the default used when one isn't provided.

e.g. split(value1)

You could also try checking the received string for spaces and replacing any found with colons and then proceed as normal.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...