Results 1 to 5 of 5

Thread: Replacing a Certain Character (resolved)

  1. #1

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228

    Replacing a Certain Character (resolved)

    Hello. I want to replace a very specific character with another
    character, going by the number. This meaning, i want to replace
    characters by which character they are.

    Lets take the string "abcdefghijklmnopqrstuvwxyz". I want to be
    able to take, say the fifth character in it ("e") and replace it with
    some other character (lets say "c"), how could i accomplish this?
    Last edited by macai; Nov 4th, 2002 at 06:27 AM.
    Luke

  2. #2
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    VB Code:
    1. sNewString = Replace("abcdefghijklmnopqrstuvwxyz","e","c")
    And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.

  3. #3

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    THat will replace every single copy of "e" with "c". I want that
    SPECIFIC copy of "e" to be replace with "c". Get where im at?
    Luke

  4. #4
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Use the Mid and InStr functions.
    Please rate my post.

  5. #5

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    VB Code:
    1. Public Function RpChr(Expression As String, ChrNm As Long, ChrRp As String)
    2.  RpChr = Left(Expression, ChrNm - 1) & Replace(Expression, Mid$(Expression, ChrNm, 1), ChrRp, ChrNm, 1)
    3. End Function
    RpChr Function
    Parameters
    Expression
    A string containing the data which will be replaced.
    ChrNm
    The character number that will be replaced.
    ChrRp
    The character which ChrNm will be replaced with.

    Example
    VB Code:
    1. x = RpChr("abcdefghijklmnopqrstuvwxyz", 5, "c")
    This will return "abcdcfghijklnmopqrstuvwxyz".
    Luke

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