使用VBA从字符串中删除字符 [英] Remove characters from a string using VBA

查看:2745
本文介绍了使用VBA从字符串中删除字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我使用下面的代码从带有下划线(_)和代码的字符串中替换($,+,&等等)字符成功替换这些字符,但我想替换不在字母A到Z和数字(1到任意数字)
之间的任何东西,而不提及我的代码中的任何字符。

I am using below code to replace characters such as ($, +, &, etc) from a string with underscore (_) and code replaces these characters successfully but i want to replace any thing that do not fall between alphabet A to Z and numbers (1 to any number) without mentioning any character in my code.

For Each varChar In Array(" ", "~", "!", "@", "#", "$", _
                        "%", "^", "&", "*", "(", ")", "-", "+", "`", "=", _
                        "{", "}", "|", "[", "]", ":", ";", """", "'", "<", _
                        ">", ",", "/")
                        strName = Replace(strName, varChar, "_")
                    Next varChar
                    
                    strName = Replace(strName, "__", "_")
                    strName = Replace(strName, "__", "_")

推荐答案

Function RemoveSpecialChars(Tekst As String) As String

        Dim a


,b


,c


这篇关于使用VBA从字符串中删除字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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