Jump to content

Extraction from a string


sejje
 Share

Recommended Posts

I have a complex (group of) string that I need to extract information from, and I'm not sure the best way and/or the syntax.

The string looks like this:

AB77777 xyzxyzxyz setinstone( 666666666), cbacbacbacbacbacba

Now, almost the entire string is variable. The only constant parts are "AB", "setinstone (" and "), "

The rest (in blue) is different every time I handle the string (these are filenames, for the record). Also, the length of the variable portions is not constant. So 77777 could also be 7777777777777.

I need to extract the variable parts (I can probably do with one example, currently I'm trying to extract 66666666 from the string).

My idea would be to find the location of each parentheses in the string, and then use Mid to extract all the values in-between them, but 1) I'm not sure this is the best way and 2) I cannot find a function to return the location of a searched string withing another string.

Any help would be greatly appreciated. I have several new wrinkles from but a few hours of mulling over this one.

Edited by sejje
Link to comment
Share on other sites

Since there are a few constants "_StringBetween" will work, else i would have used "stringregexp"

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

Since there are a few constants "_StringBetween" will work, else i would have used "stringregexp"

I saw a reference to _StringBetween before, but it is not in the function list. Am I missing something? Any link readily available?

Link to comment
Share on other sites

you need to include "string.au3"

From help file:

_StringBetween 
--------------------------------------------------------------------------------

Returns the string between the start search string and the end search string.


#include <String.au3>
_StringBetween ( $sString, $sStart, $sEnd [, $vCase [, $iSRE ]] )


 

Parameters

$sString The string to search. 
$sStart The beginning of the string to find 
$sEnd The end of the string to find 
$vCase Optional: Case sensitive search. Default or -1 is not Case sensitive else Case sensitive. 
$iSRE Optional: Toggle for regular string manipulation or StringRegExp search. Default is regular string manipulation. 

 

Return Value

Success: A 0 based $array[0] contains the first found string. 
Failure: 0 
@Error: 1 = No inbetween string found. 

 

Remarks

None.


 

Related

None. 
 

Example

#include <String.au3>
#include <array.au3>
$aArray1 = _StringBetween('[18][20][3][5][500][60]', '[', ']');Not using SRE
_ArrayDisplay($aArray1, 'Default Search')
$aArray2 = _StringBetween('[18][20][3][5][500][60]', '\[', '\]', -1, 1);Using SRE
_ArrayDisplay($aArray2, 'StringRegExp Search')
UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...