ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Replace a character by it's place in a string (https://www.excelbanter.com/excel-programming/388448-replace-character-its-place-string.html)

John Wilson

Replace a character by it's place in a string
 
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



JMB

Replace a character by it's place in a string
 
perhaps

Sub test()
Dim strTemp As String

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

End Sub


"John Wilson" wrote:

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




Jim Cone

Replace a character by it's place in a string
 

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"
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




All times are GMT +1. The time now is 06:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com