Home > Archive > ASP > March 2004 > Replace Single Character in String
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Replace Single Character in String
|
|
| Chris Hagwood 2004-03-28, 9:55 pm |
| I'm trying to use some code that was apparently written for something
else besides ASP. It has a line like this:
Mid(somestring, i, 1) = " "
This would appear to replace that character with a blank space.
How do I duplicate this in ASP? I need it to get a character at a
particular place in the string, and replace it with a blank space.
I've tried Replace(somestring, someChr, i, 1) which would supposedly
start at position i, and replace it one time. It doesn't work as
expected.
What I'm actually doing is trying to write a Soundex function, in case
you know of one out there.
How should I proceed?
| |
| McKirahan 2004-03-28, 9:55 pm |
| "Chris Hagwood" <cwh@pobox.com> wrote in message
news:4c555933.0402031251.59af21ef@posting.google.com...
> I'm trying to use some code that was apparently written for something
> else besides ASP. It has a line like this:
>
> Mid(somestring, i, 1) = " "
>
> This would appear to replace that character with a blank space.
>
> How do I duplicate this in ASP? I need it to get a character at a
> particular place in the string, and replace it with a blank space.
>
> I've tried Replace(somestring, someChr, i, 1) which would supposedly
> start at position i, and replace it one time. It doesn't work as
> expected.
>
> What I'm actually doing is trying to write a Soundex function, in case
> you know of one out there.
>
> How should I proceed?
You can't use MID to assign a character within a string but you can
construct a new string with it.
What's the problem with REPLACE?
Have you considered using Regular Expressions?
| |
| Chris Hagwood 2004-03-28, 9:55 pm |
| > You can't use MID to assign a character within a string but you can
> construct a new string with it.
>
> What's the problem with REPLACE?
I don't want it to replace all the characters, just the duplicates
that are side-by-side. In other words, mississippi would end up as
"misisipi"
I did end up using a few IF/THENs to check for XX, XXX, and XXXX, so
if a word has two to four instances of the same character in a row, it
will properly replace and remove the duplicate characters.
> Have you considered using Regular Expressions?
I should look into it if it will make my code more efficient.
|
|
|
|
|