Jump to content
Sign in to follow this  
modernes

Strip Carriage Returns

Recommended Posts

modernes

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.

Share this post


Link to post
Share on other sites
Valuater

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)


NEWHeader1.png

Share this post


Link to post
Share on other sites
modernes

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>)?

Share this post


Link to post
Share on other sites
seandisanti

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 by cameronsdad

Share this post


Link to post
Share on other sites
modernes

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?

Share this post


Link to post
Share on other sites
seandisanti

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

Share this post


Link to post
Share on other sites
modernes

Awesome - it was the @crlf, thanks for all your help!

Share this post


Link to post
Share on other sites
seandisanti

Awesome - it was the @crlf, thanks for all your help!

glad to help

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.