Queener

Extract String

8 posts in this topic

I'm not sure about how to do this. Can someone help? I have long list that piped and each of the line, I only want the string within the second and third piper. For example:

ID:9999 | James Crawler | Data Entry | Age: 19 | MTWTF|RM101

I only want to extract the James Crawler and leave out the rest.

 

 


Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites



One of possible solutions:

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

$sData='ID:9999 | James Crawler | Data Entry | Age: 19 | MTWTF|RM101'
$aSplit=StringSplit($sData,'|', $STR_NOCOUNT)

MsgBox($MB_ICONINFORMATION,'Wanted:',$aSplit[1])

 

1 person likes this

Share this post


Link to post
Share on other sites

Thank you so much, I did find another way, but I like yours.

 

;Variables to locate the right columns
$SearchString = GUICtrlRead(GUICtrlRead($List_Status))
$SearchString = _StringBetween($SearchString, "|", "|")
$SearchString = $SearchString[0]


Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites

Another possible solution (... a tribute to Rube Goldberg ;))

Local $sData = 'ID:9999 | James Crawler | Data Entry | Age: 19 | Rube Goldberg | MTWTF|RM101'

Local $iItem = 5 ; wanted item
Local $SearchString = StringMid($sData, StringInStr($sData, '|', 0, $iItem - 1) + 1, StringInStr($sData, '|', 0, $iItem) - (StringInStr($sData, '|', 0, $iItem - 1) + 1))

MsgBox(0, "Debug", $SearchString)

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Alternatives:

$sText = "ID:9999 | James Crawler | Data Entry | Age: 19 | MTWTF|RM101 "
$aExtract = StringRegExp($sText, "(.*?)\|", 3)
MsgBox(4096, "", $aExtract[1])

$sExtract = StringRegExpReplace($sText, "^.*?\|(.*?)\|.*$", "$1")
MsgBox(4096, "", $sExtract)

 

Share this post


Link to post
Share on other sites
$string = "ID:9999 | James Crawler | Data Entry | Age: 19 | MTWTF|RM101"
$extract = StringRegExpReplace($string, "^[^|]*\|([^|]*).*", "$1")
ConsoleWrite($extract)

:P

Share this post


Link to post
Share on other sites

The other solutions are better but just tossing the trimming concept out there as well ... 

$string = "ID:9999 | James Crawler | Data Entry | Age: 19 | MTWTF|RM101"
$extractLeft=stringtrimleft($string,StringInStr($string,"|"))
$extractRight=StringTrimRight($extractLeft,stringlen($extractLeft)-StringInStr($extractLeft,"|")+1)
ConsoleWrite($extractRight&@crlf)

 


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

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