Sign in to follow this  
Followers 0
Akshay07

Having troubles with _StringBetween

5 posts in this topic

#1 ·  Posted (edited)

Hello all

I am trying to use _StringBetween.

If I read the help:

#Include <String.au3>

_StringBetween($s_String, $s_Start, $s_End [, $v_Case = -1])

Parameters

$s_String The string to search.

$s_Start The beginning of the string to find. Passing a blank string starts at the beginning

$s_End The end of the string to find. Passing a blank string searches from $s_Start to end

I tried this:

$abc= "123.45"
$test = _StringBetween($abc, " ", ".")
MsgBox(0, "", $test )

I was expecting to have test="123" but the MsgBox is showing 0.

I am sure I am misunderstanding something, I just need to be told what I am misunderstanding :D

Thanks!

Edited by Akshay07

Share this post


Link to post
Share on other sites



Gave it a try, and it seems you need to pass an empty rather than a blank string !

Also, note that it returns an array

$abc= "123.45"
$test = _StringBetween($abc, "", ".")
MsgBox(0, "", $test[0] )

this returned 123 for me

whim

Share this post


Link to post
Share on other sites

Two things wrong there. _IsBetween returns an array, and you ask it to search for a space, which the string doesn't have.

You would either want a blank string ("") or you could use Int() if it's just numbers.

#Include <String.au3>

$abc = "123.45"

$test = _StringBetween($abc, "", ".")
If IsArray($test) Then
    MsgBox(0, "", $test[0])
EndIf

$test2 = Int($abc)
MsgBox(0, "", $test2)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The code I tried first is identical to post #2, I'm not running the most recent version of AutoIt (currently I'm running 3.3.0.0), is that why that code returns an error "Subscript used with non-Array variable", I know that the function is returning a 0. However, I can successfully run this code and get "123"

$abc= "123.45"
$var = StringMid($abc, 1, 1)
$test = _StringBetween($abc, $var, ".")
MsgBox(0, "", $var & $test[0] )

Edit: Ya, I've answered my question. I upgraded to 3.3.4.0 and code identical to post #2 returns "123" instead of the error..

Edited by snowmaker

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Gave it a try, and it seems you need to pass an empty rather than a blank string !

Also, note that it returns an array

$abc= "123.45"
$test = _StringBetween($abc, "", ".")
MsgBox(0, "", $test[0] )

this returned 123 for me

whim

It does return 123 for me as well, thanks! The "help" is a bit confusing as it is mentioning a blank string. "Empty string" would be more relevant in my opinion :D

Edit: I am guilty, I missed the part in the help that states "Success: A 0 based $array[0] contains the first found string. "

My bad.

Edited by Akshay07

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