Results 1 to 3 of 3

Thread: Replace Function Question

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2001
    Posts
    52

    Question Replace Function Question

    I am trying to replace nothing with something. Here is an example:

    VB Code:
    1. Dim Test as String
    2.  
    3. Test = ""
    4. Test = Replace(Test, "", "-", 1)

    If I then message Test, it still comes back with nothing. Anyone have any ideas?

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    ?? Just think about that for a minute...please....

    You want to replace every occurance of "" with something (lets say "A" for our purpose).

    Look at this string, and tell me where "" happens:

    "Hello"

    Well, it happens before H, so lets add our character there.

    "AHello"

    Now, after A, there is another ""

    "AAHello"

    Oh, look at that, another one:

    "AAAHello"

    It is a neverending loop.

    Now if you are wanting to take a empty string, and put a character, just do this:

    If Test = "" then
    Test = "-"
    End If

  3. #3
    Lively Member
    Join Date
    Aug 2003
    Location
    When?!?!
    Posts
    108
    he was giving an example to replace the occurance, not the actual code. well hellswrath is right, "" is everywhere. but the loop is not everlasting. after "" there can't be another "" because the length of "" won't fit in the string.
    DannyJoumaa
    Advanced VB6 Programmer
    Intermediate-Advanced VB .NET Programmer
    Intermediate C# Programmer
    Intermediate Win32 Developer
    Beginner Mac OS X Developer
    Contact: [email protected]

    Favorite Sayings:
    "Every time you open your mouth, you prove your an idiot."
    "God is a programmer. Satan is a bug. Life is debugging."

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