Sign in to follow this  
Followers 0
modernes

Strip Carriage Returns

8 posts in this topic

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



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

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

#4 ·  Posted (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 by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

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

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

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

glad to help

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

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  
Followers 0