Re: Replace one occurence of string within string at certain position
- From: "Karl E. Peterson" <karl@xxxxxxxxxx>
- Date: Thu, 26 Mar 2009 17:11:15 -0700
RB Smissaert wrote:
Unless I am overlooking something simple again, I don't think that will
work. The thing is I need to replace at a specified position:
Sub test()
Dim str1 As String
Dim str2 As String
str1 = "123456789"
str2 = "XX"
str1 = Replace(str1, "4", str2, 4, 1)
'I need result to be "123XX56789"
'but will get "XX56789
MsgBox str1
End Sub
Well, I'm not sure what exactly you're overlooking, but when I do this in the
Immediate Window:
?Replace("123456789", "4", "XX", 4, 1)
123XX56789
It seems to do what you say you want it to? Maybe it's that I'm taking what you say
you need too literally, and what you really need is what you allude you need? <g>
IOW, you don't care what's at position four, and it may be entirely non-unique, but
you need to replace it? Yeah, in that case, it's a mess. You can split and
concatenate. Or you can slide stuff around with CopyMemory. Is this something you
need to do repeatedly?
--
..NET: It's About Trust!
http://vfred.mvps.org
.
- Follow-Ups:
- Re: Replace one occurence of string within string at certain position
- From: Eduardo
- Re: Replace one occurence of string within string at certain position
- From: Rick Rothstein
- Re: Replace one occurence of string within string at certain position
- From: RB Smissaert
- Re: Replace one occurence of string within string at certain position
- References:
- Replace one occurence of string within string at certain position
- From: RB Smissaert
- Re: Replace one occurence of string within string at certain position
- From: Michael Williams
- Re: Replace one occurence of string within string at certain position
- From: RB Smissaert
- Re: Replace one occurence of string within string at certain position
- From: RB Smissaert
- Re: Replace one occurence of string within string at certain position
- From: Karl E. Peterson
- Re: Replace one occurence of string within string at certain position
- From: RB Smissaert
- Replace one occurence of string within string at certain position
- Prev by Date: Re: Beep Again
- Next by Date: Re: Replace one occurence of string within string at certain position
- Previous by thread: Re: Replace one occurence of string within string at certain position
- Next by thread: Re: Replace one occurence of string within string at certain position
- Index(es):
Relevant Pages
|