I recently got an irregular text file to format for further use. Part of the program I wrote tried to eliminate spaces. I used Regular Expressions to perform the job (I know, I could have used the Replace function, but the problem would have been the same)
Here's the coding excerpt:
Dim strTempNames as String
Dim objRegE As RegExp
Set objRegE = New RegExp
objRegE.Pattern = "\s"
objRegE.Global = True 'Replace them all by nothing
strTempNames = objRegE.Replace(strTempNames, vbNullString)
To my surprise, the resulting string still contained "spaces". After some investigation and dumping the memory string, I discovered that the original string contained characters represented by Hexadecimal(A0) or Char(160). The latter is a valid ANSI space character (cfr: VB6 language reference manual, ANSI character set p1148)
Therefore to be sure to eliminate spaces, use the following code fragment:
Const c_strSpaces as string = "\x20|\xA0"
Dim strTempNames as String
Dim objRegE As RegExp
Set objRegE = New RegExp
objRegE.Pattern = c_strSpaces
objRegE.Global = True 'Replace them all by nothing
strTempNames = objRegE.Replace(strTempNames, vbNullString)
PS: Be sure to set a reference to RegExp in the Project
_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
Here's the coding excerpt:
Dim strTempNames as String
Dim objRegE As RegExp
Set objRegE = New RegExp
objRegE.Pattern = "\s"
objRegE.Global = True 'Replace them all by nothing
strTempNames = objRegE.Replace(strTempNames, vbNullString)
To my surprise, the resulting string still contained "spaces". After some investigation and dumping the memory string, I discovered that the original string contained characters represented by Hexadecimal(A0) or Char(160). The latter is a valid ANSI space character (cfr: VB6 language reference manual, ANSI character set p1148)
Therefore to be sure to eliminate spaces, use the following code fragment:
Const c_strSpaces as string = "\x20|\xA0"
Dim strTempNames as String
Dim objRegE As RegExp
Set objRegE = New RegExp
objRegE.Pattern = c_strSpaces
objRegE.Global = True 'Replace them all by nothing
strTempNames = objRegE.Replace(strTempNames, vbNullString)
PS: Be sure to set a reference to RegExp in the Project
_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]