vbscript 用冒号​​分隔符分割字符串 [英] vbscript split string with colon delimiter

查看:48
本文介绍了vbscript 用冒号​​分隔符分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过 SMS 接收分隔字符串的项目.我的任务是使用 Split 函数按冒号 (:) 拆分字符串.我的 SMS 服务器接收消息并且我的脚本处理它.

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.

示例代码:

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

示例输入(短信):abc:def ghi:jkl

现在当我拆分它时,我期望 value 只返回 def,但我得到的是 defghi.为什么?

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

推荐答案

您的输出是正确的,split() 创建一个由提供的分隔符确定的子字符串数组.

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

子字符串 "def ghi" 是由于使用空格而不是冒号来分隔字符.

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

如果您不想要空格,您可以在没有给定分隔符的情况下再次使用 split," " 是未提供时使用的默认值.

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.

例如split(value1)

您也可以尝试检查接收到的字符串是否有空格并用冒号替换任何找到的字符串,然后照常进行.

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

这篇关于vbscript 用冒号​​分隔符分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆