Replace Nth Character in a String 
Author Message
 Replace Nth Character in a String

Is there some way to replace the Nth character appearing in a string with
something else, no matter what that character is?

Best Regards,
Jeffrey



Thu, 29 Apr 2004 04:45:14 GMT  
 Replace Nth Character in a String

Quote:

> Is there some way to replace the Nth character appearing in a string with
> something else, no matter what that character is?

Sure. Just use something like this:

Function ReplaceNthCharacter(MyString As String, ReplaceWith As String,
n As Integer) As String

        return left(MyString, n-1) + ReplaceWith + right(MyString,
len(MyString) - n)

End Function

Paul
--
*** PGP Key-ID: 0x54489D0D * <http://www.p-hink.de/pgp/PaulHink.asc> ***
=====================================================ICQ #: 108866612===
<http://www.p-hink.de/>: 10.11.01: * Neues Design.
~~~~~~~~~~~~~~~~~~~~~~~  06.07.01: * Korrekte Message-IDs mit MacSOUP.



Thu, 29 Apr 2004 05:18:18 GMT  
 Replace Nth Character in a String
Great! Thanks, Paul!

Best Regards,
Jeffrey


wrote on 11/10/01 1:18 PM:

Quote:

>> Is there some way to replace the Nth character appearing in a string with
>> something else, no matter what that character is?

> Sure. Just use something like this:

> Function ReplaceNthCharacter(MyString As String, ReplaceWith As String,
> n As Integer) As String

>       return left(MyString, n-1) + ReplaceWith + right(MyString,
> len(MyString) - n)

> End Function

> Paul



Thu, 29 Apr 2004 05:46:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. string.replace() can't replace newline characters???

2. Replace Characters in a String

3. Using string map to replace Special Characters (MS Word)

4. Replace a character in a string

5. Replacing characters in a string

6. Sed script to replace nth instance of >?

7. Issues with Non-COBOL characters and REPLACE / REPLACING

8. tab every nth character suggestion

9. find nth occurance in a string?

10. Building a string, character-by-character (HELP!)

11. copying character strings to smaller string

12. Fast conversion of hex string to character string

 

 
Powered by phpBB® Forum Software