Jump to content
Sign in to follow this  
some1

Get part of a variable...

Recommended Posts

some1

If $variableA = "heya.bye", how do I make $variableB just "bye", the part after the dot???

I have tried like this (I know that it is stupid, but it may give you an idea to what I'm trying to do...:

$variableA = "heya.bye"
$variableB = $variableA - "heya."

Share this post


Link to post
Share on other sites
GEOSoft

If $variableA = "heya.bye", how do I make $variableB just "bye", the part after the dot???

I have tried like this (I know that it is stupid, but it may give you an idea to what I'm trying to do...:

$variableA = "heya.bye"
$variableB = $variableA - "heya."
$variableA = "heya.bye"
$varB = StringMid($variableA, StringInStr($variableA, ".") +1)

It can also be done with RegEx but it's better to learn the basic AutoIt functions before moving on to the more advanced. Besides, no matter what programming language forum you go to, you will see what people think (in general) about RegEx.


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
some1

yay, thx for the quick reply ^^ gonna try out now

Share this post


Link to post
Share on other sites
GEOSoft

Well you have two methods to plaay with. Zedna has provided the easiest and mine is an alternate.

I should have added that I would change Zednas code just a wee bit to

$variableB = $variableB[Ubound($variableA) -1]

The reason is that it will allow for more than one period in the origional expression

as in

"heya.there.bye"

Edited by GEOSoft

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
some1

yesssss, thx guys ^^ it worked!!

EDIT:

$variableA = "heya.bye"
$variableB = StringSplit($variableA,".")
$variableB = $variableB[2]

Well you have two methods to plaay with. Zedna has provided the easiest and mine is an alternate.

I should have added that I would change Zednas code just a wee bit to

$variableB = $variableB[Ubound($variableA) -1]

The reason is that it will allow for more than one period in the origional expression

as in

But it allready worked with more seperators... or is that not what you are meaning? Edited by some1

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  

×