myspacee Posted February 23, 2010 Posted February 23, 2010 Hello to all, succesfull use StringStripCR to remove all @CR fro a txt file. My final goal is 'convert' a txt file with more rows in a new file with only one row with all text. anyone cna help me ? thank you, m.
MHz Posted February 23, 2010 Posted February 23, 2010 (edited) You can run this from your editor and see the result in the output pane. If Not @Compiled Then $string = StringReplace(FileRead(@ScriptFullPath), @CRLF, '') EndIf ConsoleWrite($string & @CRLF) Edit: Sorry, going to need to do in 2 passes with StringReplace() If Not @Compiled Then $string = StringReplace(FileRead(@ScriptFullPath), @CR, '') $string = StringReplace($string, @LF, '') EndIf ConsoleWrite($string & @CRLF) Edited February 23, 2010 by MHz
Moderators Melba23 Posted February 23, 2010 Moderators Posted February 23, 2010 myspacee, Come on, do make an effort before posting - it is not difficult! $sText = "Line 1" & @CRLF & _ "Line 2" & @CRLF & _ "Line 3" & @CRLF & _ "Line 4" & @CRLF & _ "Line 5" $sNewtext = StringReplace($sText, @CRLF, " ") ConsoleWrite($sNewtext & @CRLF) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Reveal hidden contents ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
dani Posted February 23, 2010 Posted February 23, 2010 (edited) @Melba23 & MHz He also wanted to remove @LF only if present, that only removes @CRLF. I'd recommend: $str = "Line1" & @CRLF & "Line2" & @LF & "Line3" & @CR & "Line4" $s = StringRegExpReplace($str, "\r\n|\r|\n", " ") ConsoleWrite($s) \r = @CR, \l = @LF. Added \r\n separately because it would otherwise be replaced by two spaces (once for \r, once for \n), now only one as desired. Edited February 23, 2010 by d4ni
myspacee Posted February 23, 2010 Author Posted February 23, 2010 doing some test before post, writing commnad line tool to search & replace char in text file. But stop because removing @CR with notepad i have text in a unique row, but open with worpad i have 'normal' file. So try to remove also @CRLF @LF try now StringRegExpReplace($str, "\r|\n", "") suggested by d4ni.... m.
dani Posted February 23, 2010 Posted February 23, 2010 Remember that what you are using will work but will glue words together, without spacing. If you want one space between words, you need to use the updated version of what I posted: $str = "Line1" & @CRLF & "Line2" & @LF & "Line3" & @CR & "Line4" $s = StringRegExpReplace($str, "\r\n|\r|\n", " ") ConsoleWrite($s)
myspacee Posted February 23, 2010 Author Posted February 23, 2010 Thank yuo all, use d4ni StringRegExpReplace, works perfect. thank you! m.
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