Jump to content

Strip Carriage Returns


modernes
 Share

Recommended Posts

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

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
Link to comment
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?

Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...