Sign in to follow this  
Followers 0
meisandy

Veiw string going backwards

7 posts in this topic

Hi, I can only keep this short and sweet (sorry)

Basically I've got a string (for example) "This is my string" and I want to put a routine in a loop to view the string with one letter knocked of the end. So

First loop: "This is my string"

Second loop: "This is my strin"

Third loop: "This is my stri"

...and so on until there is nothing left to veiw.

Any idea's - Thanks

P.S. When I say view I mean view! I DO NOT want the actually string to change! please

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Do you mean this?

$myString = "This is my string"

For $i = StringLen($myString) To 1 Step -1
    MsgBox(0,"My String",StringLeft($myString,$i))
Next
Edited by ajag

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

OMG, WOW, AND HOW FAST, THANKS

Share this post


Link to post
Share on other sites

Errm...sorry may I have been a bit of an over reaction because while it works it is a little to simple for me.

I need this sort of thing combined with a "Do" function. As the "To" is causing me problems.

Thanks

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Why don't you post the code that is giving you trouble? A Do/Until loop is possible, but the For loop is really better for the situation.

$sMyString = "This is a string"
$i = StringLen($sMyString)

Do
    MsgBox(0, "My String", StringLeft($sMyString, $i))
    $i -= 1
Until $i = 0
Edited by zorphnog

Share this post


Link to post
Share on other sites

Hi Zorphnog, Thanks

Sorry, I didn't think I needed to post I code. Plus, I understand The for loop would be better, but I need something more than a numetical value to end the loop!

Share this post


Link to post
Share on other sites

Sorry, I didn't think I needed to post I code [...]

Posting code always makes it much easier to help. The more I understand what you want, the more (and faster and better) I can help.

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

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