Jump to content
Sign in to follow this  

String replace wild card

Recommended Posts


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)), "|", ""))


Edited by Hatcheda

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

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 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.

Share this post

Link to post
Share on other sites

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)
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)
   $findText = StringRight($findText,(StringLen($findText)-1))
   $findText = StringLeft($string,(StringLen($string) - (StringLen($string)-StringInStr($string,$findText))))
Return $findText
Edited by mike9900

Share this post

Link to post
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
Sign in to follow this