modernes Posted December 13, 2005 Share Posted December 13, 2005 Hi, I am trying to figure out how to strip carriage returns from a string, and replace the carriage return characters with a , (comma). ie. I would go into excel, copy a column of data, then run a script to strip the carriage returns from the string placed in the clipboard and replace them with commas. Link to comment Share on other sites More sharing options...
Valuater Posted December 13, 2005 Share Posted December 13, 2005 stringreplace()... should do it example from help $text = StringReplace("this is a line of text", " ", "-") $numreplacements = @extended MsgBox(0, "New string is", $text) MsgBox(0, "The number of replacements done was", $numreplacements) 8) Link to comment Share on other sites More sharing options...
modernes Posted December 13, 2005 Author Share Posted December 13, 2005 Sweet - I didn't even see that function before. Is there any specific way to declare carriage return as a delimiter? ie. StringReplace("this is a line of text", " ", <Carriage return>)? Link to comment Share on other sites More sharing options...
seandisanti Posted December 13, 2005 Share Posted December 13, 2005 (edited) Sweet - I didn't even see that function before. Is there any specific way to declare carriage return as a delimiter? ie. StringReplace("this is a line of text", " ", <Carriage return>)?i'm not sure if it wants @cr, @lf, or @crlf as the string to be replaced, but if you wanted to do this right in excel, you could put this into the VBA editor (alt F11). this script right now just message's the results, but you could as easily have it set to another cell, or call a script with the new string as the parameter... Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) Cancel = True Dim thestring As String thestring = "" For Each Item In Selection.Cells thestring = thestring & "," & Item.Value Next Item thestring = Right(thestring, Len(thestring) - 1) MsgBox thestring, vbOKOnly, "Comma seperated" End Sub ***edit*** forgot to say, this works when you right click with multiple cells selected... Edited December 13, 2005 by cameronsdad Link to comment Share on other sites More sharing options...
modernes Posted December 13, 2005 Author Share Posted December 13, 2005 I pretty much only have to return the values from the list to another string delimited by commas. Here's the code that I have for it: $text = StringStripCR(StringReplace(ClipGet(), @CR, ",")) $response = MsgBox(262145,"Get Focus","Please select window you wish to place the string") If $response = 1 Then Send($text) EndIf The problem is that the stringstrip function is not actually removing the carriage returns from the string. Anyone seeing what I'm doing wrong? Link to comment Share on other sites More sharing options...
seandisanti Posted December 13, 2005 Share Posted December 13, 2005 I pretty much only have to return the values from the list to another string delimited by commas. Here's the code that I have for it: $text = StringStripCR(StringReplace(ClipGet(), @CR, ",")) $response = MsgBox(262145,"Get Focus","Please select window you wish to place the string") If $response = 1 Then Send($text) EndIf The problem is that the stringstrip function is not actually removing the carriage returns from the string. Anyone seeing what I'm doing wrong? try changing @CR to @CRLF or @LF Link to comment Share on other sites More sharing options...
modernes Posted December 13, 2005 Author Share Posted December 13, 2005 Awesome - it was the @crlf, thanks for all your help! Link to comment Share on other sites More sharing options...
seandisanti Posted December 13, 2005 Share Posted December 13, 2005 Awesome - it was the @crlf, thanks for all your help!glad to help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now