Results 1 to 2 of 2

Thread: Find and Replace option in string variable

  1. #1

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    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.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    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

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width