Sign in to follow this  
Followers 0
Ram

Pick text from given string

6 posts in this topic

#1 ·  Posted (edited)

Hi,

I want to create a folder name from a particular text given my user. Mostly this would be a URL and it will be same always. Just the year will be changed.

For e.g:

http://www.internalLink.com//archive/text.php?lang=English&yr=1995&mnth=8&adOpt=0

From the url = I want to extract - Word "English", year = 1995 and month= 8

Combine all the three to make a folder. Is this possible? if so how?

BTW: The url is going to be the same - just that three items = English, 1995, 8 will be changed.

I was looking at the examples for StringRegExp couldn't understand a bit - look complicated :) - an example simple way would help me out!

Awaiting your response!

Thanks!

Edited by Ram

Share this post


Link to post
Share on other sites



Ram,

See stringinstr..

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Here's a way:

#include <array.au3>
#include <string.au3>
$string = "http://www.internalLink.com//archive/text.php?lang=English&yr=1995&mnth=8&adOpt=0"

$string1 = _StringBetween($string, "=", "&")

;_ArrayDisplay($string1) ; This is the array returned

$newString = $string1[0] & "_" & $string1[1] & "_" & $string1[2]

MsgBox(0, "", "Your final string is:" & @CRLF & $newString)

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

Here's a way:

#include <array.au3>
#include <string.au3>
$string = "http://www.internalLink.com//archive/text.php?lang=English&yr=1995&mnth=8&adOpt=0"

$string1 = _StringBetween($string, "=", "&")

;_ArrayDisplay($string1) ; This is the array returned

$newString = $string1[0] & "_" & $string1[1] & "_" & $string1[2]

MsgBox(0, "", "Your final string is:" & @CRLF & $newString)

Wow.. I didn't know there is something called _StringBetween.

This is what I was expecting... Good that the url has a "=" to "&" after the string that I want to pick up..

Great. Thanks a lot!!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ram,

If you are curious, this is one way for regexp to do this:

local $mystr = "[url="http://www.internallink.com//archive/text.php?lang=English&yr=1995&mnth=8&adOpt"]http://www.internalLink.com//archive/tex...xt.php?lang=English&yr=1995[/url]"
local $a_10  = stringregexp($mystr,"=(.*?)&",3)
if @error <> 0 then msgbox(1,'REGEXP ERROR',@error)
#cs
=       find "="
(.*?)   get all chars until
&       you find an "&"
repeat this until no more matches
each element in the array will match the capturing groups in order that they are found
#ce
consolewrite('lang = ' & $a_10[0] & @lf & 'yr = ' & $a_10[1] & @lf & 'mnth = ' & $a_10[2] & @lf)

kylomas

Edit: code editor is not showing all code...use the "popup" button to see the last line

edit2: if you try this supply a new string, this $%^^&## editor screwed the origional up!!

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Ram,

If you are curious, this is one way for regexp to do this:

local $mystr = "[url="http://www.internallink.com//archive/text.php?lang=English&yr=1995&mnth=8&adOpt"]http://www.internalLink.com//archive/tex...xt.php?lang=English&yr=1995[/url]"
local $a_10  = stringregexp($mystr,"=(.*?)&",3)
if @error <> 0 then msgbox(1,'REGEXP ERROR',@error)
#cs
=       find "="
(.*?)   get all chars until
&       you find an "&"
repeat this until no more matches
each element in the array will match the capturing groups in order that they are found
#ce
consolewrite('lang = ' & $a_10[0] & @lf & 'yr = ' & $a_10[1] & @lf & 'mnth = ' & $a_10[2] & @lf)

kylomas

Edit: code editor is not showing all code...use the "popup" button to see the last line

edit2: if you try this supply a new string, this $%^^&## editor screwed the origional up!!

wow. This is also worked. Thanks a lot kylomas. I changed few things and written my own code and works just fine!!

It is Strange the code editor is giving issues when posting!! :)

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  
Followers 0