Find and Replace option in string variable
Hi all,
I know we can use Replace function, "Replace(expression, find, replace[, start[, count[, compare]]])" to find and replace a char/digit etc.
For example, I want to remove all the symbols, comma, full stop, $ sign, blank space, not printable characters etc.
"I am currently reading "$56 in an hour" Book."
Let say the above sentence is stored in a variable. I need to change it to
Iamcurrentlyreading56inanhourBook
How can I do that?
Pls let me know.
Thanks,
CS.
Re: Find and Replace option in string variable
Either
- a list of replace statements.
- a loop through a previously set up array of chars using a loop and replace
- code to go through your string, character by character and compare the characters to see if they are a-z, A-Z, 0-9. Those that are in that range would then be added to an output string.
It would be something like the following...
Code:
public function ReplaceAllOtherChars(byval strInput as string) as string
dim strOutput as string, strChar as string
dim lngLen as long, lngPos as long
on error resume next
stroutput = ""
lnglen = len(strinput)
if lnglen>0 then
for lngpos = 1 to lnglen
strchar = mid(strinput,lngpos,1)
if strchar like "[a-z,A-Z,0-9]" then stroutput=stroutput & strchar
next
end if
ReplaceAllOtherChars = stroutput
end function