Jump to content
Sign in to follow this  
ravenfyre

StringinStr, search from right not working

Recommended Posts

ravenfyre

Howdy folks. I'm using StringinStr and would like to search from the right, instead of the left. Taken directly from the help file, "Use a negative occurance to search from the right side." Unfortunately it doesn't work, I still get results from the left hand side of the string. Just run my simple example and see.

StringInStr ( "string", "substring" [, casesense [, occurance]] )

$test = "3,2,1"
$num = 1;

$check = StringInStr($test,$num,0,-1);

msgbox(0, "test", "should be 1: "&$check);

It should be 1, not 5, if it searched from the right. A bug, or am I overlooking something?

Edited by ravenfyre

Share this post


Link to post
Share on other sites
Holger

No, that is not a bug.

It's not necessary from which side you're searching for a string, the string position will be ever the same!.

("Success: Returns the position of the substring.")

Edited by Holger

Share this post


Link to post
Share on other sites
ravenfyre

Hmm that's kinda odd. Oh well I guess that would be the easy way out ^^.

Share this post


Link to post
Share on other sites
Jos

Hmm that's kinda odd.  Oh well I guess that would be the easy way out ^^.

<{POST_SNAPBACK}>

Its not really "the easy way out" but its the way all string functions work.

It would be more difficult to use other String commands when it would return the found position seen from the right, since they all use the position from the left.

Just an example:

Assume you want to find the last octet of an IP address:

$IP = "192.168.0.213"
$oct4 = StringTrimLeft($IP,StringInStr($IP,".",0,-1))
MsgBox(0,'ip',$oct4)

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
this-is-me

You could do StringLen($test) - $check


Who else would I be?

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.