Hi -
Given a string which contains spaces and special characters - i.e. @, #, $, %, ^, ., etc. - I want to convert the string from, say, "TEMP. HOT WATER #2" to "TEMP_HOT_WATER_2", for example. Essentially, I want to replace all spaces and special characters with "_". However, I do not want two underscores in a row. The code so far goes something like:
Following this section, I'd like to go through the adjusted string and remove any extra underscores that may exist (i.e. if a space lies next to a special character, two underscores will be inserted as replacements).
Is there a way to access specific characters within a string so as to remove any duplicate adjacent characters? I've tried using a For...Next loop along with some combinations of Right(Left(xxx), x) statements, but it all seems so convoluted.
Any ideas? Thanks in advance!
Given a string which contains spaces and special characters - i.e. @, #, $, %, ^, ., etc. - I want to convert the string from, say, "TEMP. HOT WATER #2" to "TEMP_HOT_WATER_2", for example. Essentially, I want to replace all spaces and special characters with "_". However, I do not want two underscores in a row. The code so far goes something like:
Code:
Title1 = Forms!Search!SearchResults.Column(2)
NullTitle1 = IsNull(Title1)
If NullTitle1 = True Then
Title1 = ""
Else
'Replace special characters
Title1 = Replace(Title1, "-", "_")
Title1 = Replace(Title1, "&", "_")
Title1 = Replace(Title1, " ", "_")
Title1 = Replace(Title1, "#", "_")
Title1 = Replace(Title1, ".", "_")
...
etc.
End If
Following this section, I'd like to go through the adjusted string and remove any extra underscores that may exist (i.e. if a space lies next to a special character, two underscores will be inserted as replacements).
Is there a way to access specific characters within a string so as to remove any duplicate adjacent characters? I've tried using a For...Next loop along with some combinations of Right(Left(xxx), x) statements, but it all seems so convoluted.
Any ideas? Thanks in advance!