anixon Posted October 25, 2009 Share Posted October 25, 2009 I have a string which looks like this: aaaa<space>123456<crlf> bbbb:<space>1234<space>1234<space>1234<space>1234<crlf> cccc:<space>This is text Which I want to convert to this: aaaa|123456|bbbb:|1234|1234|1234|1234|cccc:|This is text This code does not work: $Text = StringRegExpReplace($String, "\s+", "|") and neither does this work: $Text = StringRegExpReplace($String, "[\r\n]+", "|") $Text = StringReplace($Text, " ", "|") Assistance is always appreciated Ant.. Link to comment Share on other sites More sharing options...
monoceres Posted October 26, 2009 Share Posted October 26, 2009 (edited) Even I managed to do it $str=StringRegExpReplace("hello you"&@CRLF&"is here","\s","|") MsgBox(0,"",$str) Edited October 26, 2009 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
martin Posted October 26, 2009 Share Posted October 26, 2009 I have a string which looks like this: aaaa<space>123456<crlf> bbbb:<space>1234<space>1234<space>1234<space>1234<crlf> cccc:<space>This is text Which I want to convert to this: aaaa|123456|bbbb:|1234|1234|1234|1234|cccc:|This is text This code does not work: $Text = StringRegExpReplace($String, "\s+", "|") and neither does this work: $Text = StringRegExpReplace($String, "[\r\n]+", "|") $Text = StringReplace($Text, " ", "|") Assistance is always appreciated Ant.. If the string is as you have written it then there is no \r\n to replace because these are represented by <crlf> But I suspose you have just done that so we can see them. Assuming there really is @CRLF there instead of <crlf> and a space instead of <space> then your RegExp examples work. Either way I think in this case it is easier to use StringReplace $Text = STringReplace($Text,'<crlf>','|') $Text = STringReplace($Text,'<space>','|') ;OR $Text = STringReplace($Text,@CRLF,'|') $Text = STringReplace($Text,' ','|') Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
anixon Posted October 26, 2009 Author Share Posted October 26, 2009 If the string is as you have written it then there is no \r\n to replace because these are represented by <crlf> But I suspose you have just done that so we can see them. Assuming there really is @CRLF there instead of <crlf> and a space instead of <space> then your RegExp examples work. Either way I think in this case it is easier to use StringReplace $Text = STringReplace($Text,'<crlf>','|') $Text = STringReplace($Text,'<space>','|') ;OR $Text = STringReplace($Text,@CRLF,'|') $Text = STringReplace($Text,' ','|') The text is contained within an email when copied to Word the formatting marks representing a <space> are either a degree mark <as in degrees minutes> as well as what looks like a hyphen. They marks do not alternate and appear randomly between each character This code will convert the degrees to "|" but not the other formatting mark '-' MsgBox(0, "Regular Expression Replace Test", StringRegExpReplace($text, "[\s ]+", "|")) Link to comment Share on other sites More sharing options...
GEOSoft Posted October 26, 2009 Share Posted October 26, 2009 $sText = StringRegExpReplace($sText, "(\s+), "|") George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
anixon Posted October 26, 2009 Author Share Posted October 26, 2009 $sText = StringRegExpReplace($sText, "(\s+), "|") The embedded code [viewed in Word] within the email text for a space can be either the degree symbol [as in degrees minutes] or what looks like a hyphen '-' your code will convert the '-' representing a space to "|" but not the degree symbol representing a space. 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