John117 Posted June 10, 2008 Share Posted June 10, 2008 (edited) I would like to replace everything after "|" with "" How can I do this. I have this so far. I am looking for a "Wild Card" such as "*" I can not depend on trim since the strings are not common, and vary in length and placement of "|" So really all I want to keep is everything before "|" MsgBox(64, "OK ",StringReplace(GUICtrlRead(GUICtrlRead($listviewID)), "|", "")) Thanks! Edited June 11, 2008 by Hatcheda Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 10, 2008 Moderators Share Posted June 10, 2008 StringRegExpReplace($sString, "\|.*?", "") Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
martin Posted June 10, 2008 Share Posted June 10, 2008 (edited) StringRegExpReplace($sString, "\|.*?", "") Maybe that should be $Ans = StringRegExpReplace($sString, "\|.*", "") & '|' or if you don't want the '|' included then $Ans = StringRegExpReplace($sString, "\|.*", "") ANother way is $Ans = stringleft($sString,stringinstr($sString,'|')) or, again, if you don't want the '|' then $Ans = stringleft($sString,stringinstr($sString,'|') - 1) Edited June 10, 2008 by martin 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...
John117 Posted June 11, 2008 Author Share Posted June 11, 2008 @ All -Thank ya - Both worked! Link to comment Share on other sites More sharing options...
mike9900 Posted June 9, 2012 Share Posted June 9, 2012 (edited) Sorry for the resurrection of an old post..... I'm no good at RegEx, and I wrote this to get around it using StringReplace. Hope this makes sense. Might not be the best looking piece of code, but it does what the OP asks. $string = "This is the text I want to keep|This is the text I want to delete" $findText = "|*" $replaceText = "" $newString = StringReplace($string,WildCardFindText($findText,$string),$replaceText) MsgBox(0,"New",$newString) Func WildCardFindText($findText, $string) If StringInStr($findText,"*") > 0 Then $WildCardPosition = StringInStr($findText,"*") If $WildCardPosition = StringLen($findText) Then $findText = StringLeft($findText,(StringLen($findText)-1)) $findText = StringRight($string,(StringLen($string)-StringInStr($string,$findText))+1) Else $findText = StringRight($findText,(StringLen($findText)-1)) $findText = StringLeft($string,(StringLen($string) - (StringLen($string)-StringInStr($string,$findText)))) EndIf EndIf Return $findText EndFunc Edited June 9, 2012 by mike9900 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