Sign in to follow this  
Followers 0
danpaul23

string between question

17 posts in this topic

I'm trying to use the _StringBetween function but I would like to start the search from what would normally be the end and search backwards in the string to what would normally be the start.

I need to do this without using the _StringReverse function.

Thanks,

Dan

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I can't understand why you wouldn't use _StringReverse. It would work perfectly if you stringbetween it and reverse. I don't think I know another way

Edited by _Kurt

Awaiting Diablo III..

Share this post


Link to post
Share on other sites

I can't understand why you wouldn't use _StringReverse. It would work perfectly if you stringbetween it and reverse. I don't think I know another way

Because it's searching the HTML source for a large page.

Share this post


Link to post
Share on other sites

Well, do you want to read the WORDS backwards? or each letter backwards?

example: hello this is a test

returns: test a is this hello


Awaiting Diablo III..

Share this post


Link to post
Share on other sites

Well, do you want to read the WORDS backwards? or each letter backwards?

example: hello this is a test

returns: test a is this hello

hey i dont understand, how can you read each letter backwords? :">


Announceing a line of new Apple products: the iDontCare and the iSuck, with the code based off their iCrashtoHellAlot ox.10, with a new GUI based on a zebra, panda bear, coyote, lollipop, and a can of tuna.

Share this post


Link to post
Share on other sites

Well, do you want to read the WORDS backwards? or each letter backwards?

example: hello this is a test

returns: test a is this hello

I assume that if it was possible to do a reverse search I would have to reverse the strings which represented the "start" and "end" points of the backward search and that the string I would get would also be reversed (letter by letter).

So, I guess, I would want it to read the letters backwards, since then I could easily reverse the string and get the results I wanted.

I think I may have figured out a bit of a sloppy way to get around having to do this but it would be easier and cleaner to just be able to search backwards.

Thanks.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

A sloppy way would perhaps look something like this (this is just a small example):

SNIPPED, see post below

I'm not 100% sure that could work, but I bet something like that would.

Hope that helps,

Kurt

EDIT: minor mistake

Edited by _Kurt

Awaiting Diablo III..

Share this post


Link to post
Share on other sites

A sloppy way would perhaps look something like this (this is just a small example):

Local $string = ""
$len = StringLen($yourstring)
For $i = 1 To $len
   $string = $string & StringTrimLeft($yourstring, $len+$i)
Next
Msgbox(0,"","This a small attempt to reverse the letters in your string:" & @CRLF & $string)

I'm not 100% sure that could work, but I bet something like that would.

Hope that helps,

Kurt

it doesn't :) but i see what you mean. hehe

Announceing a line of new Apple products: the iDontCare and the iSuck, with the code based off their iCrashtoHellAlot ox.10, with a new GUI based on a zebra, panda bear, coyote, lollipop, and a can of tuna.

Share this post


Link to post
Share on other sites

A sloppy way would perhaps look something like this (this is just a small example):

Local $string = ""
$len = StringLen($yourstring)
For $i = 1 To $len
   $string = $string & StringTrimLeft($yourstring, $len-$i)
Next
Msgbox(0,"","This a small attempt to reverse the letters in your string:" & @CRLF & $string)

I'm not 100% sure that could work, but I bet something like that would.

Hope that helps,

Kurt

EDIT: minor mistake

I'll have to look at it more closely later (I've got one foot out the door.) but I think it won't work since prior to completing the _stringbetween function, the size of the string is not known.

It has got me thinking about some other options I could maybe use however and as I said, if all else fails, I think I have another sloppy solution that will at least work.

Thanks again.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I've got it!!!

Local $string = "", $yourstring = "tset a si siht"
$len = StringLen($yourstring)
For $i = 1 To $len
   $trimleft = StringTrimLeft($yourstring, $len-$i)
   $trimright= StringTrimRight($trimleft, $i-1)
   $string = $string & $trimright
Next
Msgbox(0,"","This a small attempt to reverse the letters in your string:" & @CRLF & $string)

EDIT: it also works at VERY fast speed :) -- the Msgbox is " this is a test "

Edited by _Kurt

Awaiting Diablo III..

Share this post


Link to post
Share on other sites

I've got it!!!

Local $string = "", $yourstring = "tset a si siht"
$len = StringLen($yourstring)
For $i = 1 To $len
   $trimleft = StringTrimLeft($yourstring, $len-$i)
   $trimright= StringTrimRight($trimleft, $i-1)
   $string = $string & $trimright
Next
Msgbox(0,"","This a small attempt to reverse the letters in your string:" & @CRLF & $string)

EDIT: it also works at VERY fast speed :) -- the Msgbox is " this is a test "

nice job!

Announceing a line of new Apple products: the iDontCare and the iSuck, with the code based off their iCrashtoHellAlot ox.10, with a new GUI based on a zebra, panda bear, coyote, lollipop, and a can of tuna.

Share this post


Link to post
Share on other sites

Yes, we know xcal. I've got no clue why danpaul doesn't use _StringReverse() but it's up to him. And my way works perfectly, and at a fast speed :)


Awaiting Diablo III..

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I realize that... I just thought it was odd to request a resolution to something that already has a resolution.

MsgBox(0, '', _StringReverse('tset a si siht'))

;right out of string.au3
Func _StringReverse($sString)
    Local $sReverse
    Local $iCount
    If StringLen($sString) >= 1 Then
        For $iCount = 1 To StringLen($sString)
            $sReverse = StringMid($sString, $iCount, 1) & $sReverse
        Next
        Return $sReverse
    Else
        SetError(1)
        Return ""
    EndIf
EndFunc
Edited by xcal

Share this post


Link to post
Share on other sites

Lol, that is true. It's basically the same thing, oh well.

Kurt

PS: i like your new pic, xcal :)


Awaiting Diablo III..

Share this post


Link to post
Share on other sites

I've got it!!!

Local $string = "", $yourstring = "tset a si siht"
$len = StringLen($yourstring)
For $i = 1 To $len
   $trimleft = StringTrimLeft($yourstring, $len-$i)
   $trimright= StringTrimRight($trimleft, $i-1)
   $string = $string & $trimright
Next
Msgbox(0,"","This a small attempt to reverse the letters in your string:" & @CRLF & $string)

EDIT: it also works at VERY fast speed :) -- the Msgbox is " this is a test "

Thanks for working on this and the interesting solution however, it's not what I'm looking for. Basically I have a large source that I'm searching that looks something like this.

...............<A>.............<A>..............<A>.........(unknown size and content)..............<B>...................<A>

I need the string between the third <A> and the <B>. <B> is a unique expression which I know. I also know <A> but it is a common expression which occurs a lot through the document so I don't want to search for the string between <A> and <B> because it returns all the <A> to <B> strings from the start of the document. I don't want to use string reverse for the entire file because it seems to take a long, long time to do so (it's a large file).

If I could search from the <B> backwards to the third <A>, it would be an easy solution.

I think my imperfect solution is going to be to search for the string from <A> to <B> then sort the array which is created from the <A> to <B> string search so that the smallest string is on top, then use that.

I was also thinking that if I could extract the charecters one at a time from the left of expression <B> to create a string, I would eventually be able to "find" <A> and then reverse the string generated (hope that makes sense). But I'm not sure if that would be any more efficient than just generating and sorting a big array of strings.

I've only been writing code for about a week so I might be missing something obvious or have entirely misunderstood something. Sorry if that's the case.

Thanks again.

Share this post


Link to post
Share on other sites

Thanks for working on this and the interesting solution however, it's not what I'm looking for. Basically I have a large source that I'm searching that looks something like this.

...............<A>.............<A>..............<A>.........(unknown size and content)..............<B>...................<A>

I need the string between the third <A> and the <B>. <B> is a unique expression which I know. I also know <A> but it is a common expression which occurs a lot through the document so I don't want to search for the string between <A> and <B> because it returns all the <A> to <B> strings from the start of the document. I don't want to use string reverse for the entire file because it seems to take a long, long time to do so (it's a large file).

If I could search from the <B> backwards to the third <A>, it would be an easy solution.

I think my imperfect solution is going to be to search for the string from <A> to <B> then sort the array which is created from the <A> to <B> string search so that the smallest string is on top, then use that.

I was also thinking that if I could extract the charecters one at a time from the left of expression <B> to create a string, I would eventually be able to "find" <A> and then reverse the string generated (hope that makes sense). But I'm not sure if that would be any more efficient than just generating and sorting a big array of strings.

I've only been writing code for about a week so I might be missing something obvious or have entirely misunderstood something. Sorry if that's the case.

Thanks again.

I actually found a pretty simple solution and thought I'd post it in case anyone in the future is trying to figure out the same thing. There are probably better ways to write it but this should at least demonstrate the idea.

CODE
$VarA = 0

$days = StringSplit("Sun,Mon,Tue,Wed,Thu,Fri,Sat", "Thu", 1)

$String2 = string($days[1])

While 1

$VarA = $VarA + 1

$String3 = StringRight ($String2, $VarA)

$result = STringInStr($String3, "Sun")

if not ($result = 0) Then

exitloop

EndIf

WEnd

MsgBox(0,"", "your string, sir: " & $String3)

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