anixon Posted February 2, 2009 Share Posted February 2, 2009 Have been unable to get my mind around this one even after studying string processing in Help. If a string contains CRLF CR and/or multiple spaces how do you replace these non typing characters with a single space. For example what code would you use to change this text string: Before : 'This is an example of the text to be fixed' After: 'This is an example of the text to be fixed' Help is always appreciated Link to comment Share on other sites More sharing options...
FireFox Posted February 2, 2009 Share Posted February 2, 2009 @anixon $delCRLF = StringReplace($s_string, @CRLF, ' ') $delCR = StringReplace($delCRLF, @CR, ' ') MsgBox(64, 'StringReplace', $delCR) Not tested, Cheers, FireFox. Link to comment Share on other sites More sharing options...
anixon Posted February 2, 2009 Author Share Posted February 2, 2009 (edited) @anixon $delCRLF = StringReplace($s_string, @CRLF, ' ') $delCR = StringReplace($delCRLF, @CR, ' ') MsgBox(64, 'StringReplace', $delCR) Not tested, Cheers, FireFox. Thanks for that works with cr and crlf what about if the text contains multiple spacing like test.....and this was..........the result. Please read the periods 'full stops' as spaces Ant.. Edited February 2, 2009 by anixon Link to comment Share on other sites More sharing options...
Spiff59 Posted February 2, 2009 Share Posted February 2, 2009 (edited) Or maybe: $str = @CR & " This is a test " & @CR & @CRLF & " . " $str = StringStripWS($str ,7) Msgbox(1,"",$str) EDIT: Oops, typo Edited February 2, 2009 by Spiff59 Link to comment Share on other sites More sharing options...
anixon Posted February 2, 2009 Author Share Posted February 2, 2009 This is a combination of both codes that does the requested task. Thanks for your help. CODE$s_string = "This is test" & @crlf & "to see whats what" & @crlf & "whats what again" $delCRLF = StringReplace($s_string, @CRLF, ' ') $delCR = StringReplace($delCRLF, @CR, ' ') $str = StringStripWS($delCR ,7) Msgbox(1,"",$str) Link to comment Share on other sites More sharing options...
Spiff59 Posted February 2, 2009 Share Posted February 2, 2009 This is a combination of both codes that does the requested task. Thanks for your help.CODE$s_string = "This is test" & @crlf & "to see whats what" & @crlf & "whats what again"$delCRLF = StringReplace($s_string, @CRLF, ' ')$delCR = StringReplace($delCRLF, @CR, ' ')$str = StringStripWS($delCR ,7)Msgbox(1,"",$str)If you read the help file on StingStripWS, it by itself removes:Chr(9) thru Chr(13) which are HorizontalTab, LineFeed, VerticalTab, FormFeed, CarriageReturn, the null string "" (Chr(0)) and the standard space " " (Chr(32)) Link to comment Share on other sites More sharing options...
BrettF Posted February 2, 2009 Share Posted February 2, 2009 $s_string = "This is test" & @crlf & "to see whats what" & @crlf & "whats what again" $str = StringRegExpReplace ($s_string, "\s+", " ") Msgbox(1,"",$str) I'm getting better at this RegExp stuff me thinks! Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
anixon Posted February 2, 2009 Author Share Posted February 2, 2009 $s_string = "This is test" & @crlf & "to see whats what" & @crlf & "whats what again" $str = StringRegExpReplace ($s_string, "\s+", " ") Msgbox(1,"",$str) I'm getting better at this RegExp stuff me thinks! You can say that again reducing a number of steps into a single line of code I am humbled by the experience Ant.. 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