Jump to content
Sign in to follow this  
wimhek

String Split

Recommended Posts

wimhek

How can I do a string split on a delimiter longer than 1 pos ?

F. i. I have a string :

$a ="<href=blah di bla <href=asdsdadsda <href=........."

And I want to do a stringsplit on '<href='

e.g.

$b=stringsplit($a,'<href=')

thnx

Share this post


Link to post
Share on other sites
Bowmore

How can I do a string split on a delimiter longer than 1 pos ?

F. i. I have a string :

$a ="<href=blah di bla <href=asdsdadsda <href=........."

And I want to do a stringsplit on '<href='

e.g.

$b=stringsplit($a,'<href=')

thnx

$b=stringsplit($a,'<href=',1) wiil do the job

_StringBetween() might also be worth checking out for what you require.

Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites
GEOSoft

How can I do a string split on a delimiter longer than 1 pos ?

F. i. I have a string :

$a ="<href=blah di bla <href=asdsdadsda <href=........."

And I want to do a stringsplit on '<href='

e.g.

$b=stringsplit($a,'<href=')

thnx

$a = StringReplace($a, "<href=", "|")
$b = StringSplit($a, "|")

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!"

Share this post


Link to post
Share on other sites
unixu

How can I do a string split on a delimiter longer than 1 pos ?

F. i. I have a string :

$a ="<href=blah di bla <href=asdsdadsda <href=........."

And I want to do a stringsplit on '<href='

e.g.

$b=stringsplit($a,'<href=')

thnx

depens and why you need to split = do you want to cut out the url then i would use stringinstr and stringregexp

Share this post


Link to post
Share on other sites
wimhek

$b=stringsplit($a,'<href=',1) wiil do the job

_StringBetween() might also be worth checking out for what you require.

Thank you, the _stringbetween did the job, however, how can I process the table, as I dont kow how many elements ate in the array. (With stringsplit, I get the number of elements in the first arrayline)

Share this post


Link to post
Share on other sites
Bowmore

Thank you, the _stringbetween did the job, however, how can I process the table, as I dont kow how many elements ate in the array. (With stringsplit, I get the number of elements in the first arrayline)

Use Ubound.

Two examples for you

#include <string.au3>
;Using StringBetwen
$aData = _StringBetween("<href=blah di bla <href=asdsdadsda <href=.........","ref=","<h")
For $i = 0 To UBound($aData) -1
    MsgBox(0,"Values",  $aData[$i])
Next

;Using String split
;Note:returns "" in element 1 and "......." in last element
$aData = StringSplit("<href=blah di bla <href=asdsdadsda <href=.........","<href=",1)
For $i = 1 To UBound($aData) -1
    MsgBox(0,"Values",  $aData[$i])
Next

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites
Richard Robertson

A regular expression would help too.

$matches = StringRegexp($yourstring, 'href="([^"]*)"', 1)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.