Jump to content
Sign in to follow this  
edgariyu

Help with Trims

Recommended Posts

edgariyu

Hi everyone! I've a doubt (think it's a bit rookie) but i'm in fact rookie with Autoit ;)

My doubt is that i'm trying to use StringTrimLeft with a variable that contains a string and doesn't work.

If you use the function with the string "+something+something", and you want to trim the first character there's no problem, but if you use a var like $foo = "+something+something" and then you want to trim it like StringTrimLeft($foo,1) there's no trim after using the function.

I would like to know if there's any way to do that (abviously i'm using a var because the value i'm expecting changes every spin of the loop).

Thanks in advance :blink:

Share this post


Link to post
Share on other sites
somdcomputerguy

This works OK for me

$foo = "+something+something"
MsgBox(4096, "", $foo & @LF & @LF & StringTrimLeft($foo,1))
Edited by somdcomputerguy

- 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
ajag

Please post the code that doesn't work.


Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Share this post


Link to post
Share on other sites
edgariyu

It's part of a big code, but the values of $KW comes from a ExcelReadCell of an Excel sheet and are of the tipe foo,fooo

The trim is inside the first conditional, after the For bucle.

For $j=1 To UBound($KW) Step +1
      For $i=2 To UBound($KW) Step +1
        If $KW[$i][$j] <> "*" Then
            $split=StringSplit($KW[$i][$j],",") 
                $query=""
                For $z=1 To $split[0] Step +1
                    ConsoleWrite($split[$z] & @CRLF)
                    $query = $query & "+" & $split[$z]
                Next

                StringTrimLeft($query,1)
                $queries[$count] = $query
                                ConsoleWrite ("any changes?: " & $queries[$count])
                $count+=1
        Else ; no hay mas KW en esta temática
            If ($KW[$i][$j] = "*") Then
                ExitLoop
            EndIf
        EndIf   
    Next

    If ($KW[1][$j+1] = "*") Then
        ExitLoop
    EndIf
Next

I don't know why your example works, but when i try with my code doesn't work :s

Thanks for your help!!

Share this post


Link to post
Share on other sites
somdcomputerguy

I suspect it is working correctly, but you are not displaying the return value of StringTrimLeft.

Change

StringTrimLeft($query,1)

to

ConsoleWrite(StringTrimLeft($query,1) & @LF)

and it should work as expected.


- 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
ajag

So you should write

$query = StringTrimLeft($query,1)

A-Jay


Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Share this post


Link to post
Share on other sites
somdcomputerguy

I was just thinking that too.. Instead of ConsoleWriting it out.


- 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
edgariyu

Great guys!!

Thanks a lot for your help :blink:

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.