Replace a character by it's place in a string

J

John Wilson

Hoping there's an easy way to do this.
Tried the hard way (Left, Right) and it works but I was looking
for an easier way.

I need to replace a character in a string by it's position in the string.

i.e.
String = "aaaaaaaa"
Replace the 5th character with "Chr(10)"

Result = "aaaa(Chr(10))aaa"

Thanks for your help
 
J

JMB

perhaps

Sub test()
Dim strTemp As String

strTemp = "aaaaaaaa"
strTemp = Application.Replace(strTemp, 5, 1, Chr(10))
MsgBox strTemp

End Sub
 
J

Jim Cone

Here is one way...
Sub abc()
Dim str As String
str = "aaaaaaaa"
Mid$(str, 5, 1) = Chr$(10)
MsgBox str
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"John Wilson" <[email protected]>
wrote in message
Hoping there's an easy way to do this.
Tried the hard way (Left, Right) and it works but I was looking
for an easier way.
I need to replace a character in a string by it's position in the string.
i.e.
String = "aaaaaaaa"
Replace the 5th character with "Chr(10)"
Result = "aaaa(Chr(10))aaa"
Thanks for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top