如何从 VBscript 中的字符串中删除字符
我是 vbscript 和 Stack Overflow 的新手,确实需要一些帮助。
目前,我正在尝试格式化从图像读取并存储在变量中的电话号码。因为图像是“脏”的,所以会出现额外的字符,例如句号或括号。我已经尽可能地限制了该字段,以防止拾取额外的字符,但是唉!
例如我想将“,123.4567890”转换为“123 456 7890”(不包括双引号)。问题是我不知道可能会选取哪些额外的字符,从而排除了简单的替换。
我的逻辑是删除所有非数字字符,从左侧开始,在第三个数字后插入一个空格,在第六个数字后插入一个空格。
任何帮助都会很棒,如果需要,请随时询问更多信息。
I'm new to vbscript and Stack Overflow, and could really use some help.
Currently I'm trying to format a phone number that is read from an image and stored in a variable. Because the images are "dirty" extra characters find their way in, such as periods or parenthesis. I've already restricted the field as much as possible to help prevent picking up extra characters, but alas!
For example I want to turn ",123.4567890" into "123 456 7890" (not including the double quotes). Trouble is I won't know what extra characters could potentially be picked up, ruling out a simple replace.
My logic is remove any non numeric characters, start from the left, insert a space after the third number, insert a space after the sixth number.
Any help would be great, and please feel free to ask for more information if needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
欢迎来到堆栈溢出。您可以使用 Regex 和 使用 连接 各部分中功能。
例如:
或完全使用正则表达式(通过第二个分组模式):
Welcome to Stack Overflow. You can remove non-digits using Regex, and concatenate the parts using Mid function.
For example:
Or fully using Regex (via a second grouping pattern):
使用第一个正则表达式来清除输入中的非数字,第二个正则表达式使用布局组来清除:
Use a first RegExp to clean non-digits from the input and second one using groups for the layout: