Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace font of one character in a string PaulS Excel Programming 3 January 13th 07 03:45 AM
How replace a character in a string of characters? Chet Excel Programming 6 December 6th 06 01:54 AM
Replace character in string, not document KS[_2_] Excel Programming 3 October 26th 06 05:06 PM
Function to return Character Position of Xth character within a string Andibevan[_2_] Excel Programming 4 June 9th 05 03:24 PM
How do I replace * as a character in a string in Excel? nicolegt Excel Programming 1 January 21st 05 10:42 AM


All times are GMT +1. The time now is 07:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"