Jump to content

From a string to a dif string


Recommended Posts

Is there a way to get characters between two given strings? For example:

I want to go to school now.

If i wanted to see where they wanted to go do like

StringBetween("to ", " now") And it would return school.

(Stupid example and i know theres no such thing as "stringbetween")

My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]
Link to comment
Share on other sites

There is in my world:

Func stringbetween($str, $start, $end)
    $pos = StringInStr($str, $start)
    If Not @error Then
        $str = StringTrimLeft($str, $pos + StringLen($start) - 1)
        $pos = StringInStr($str, $end)
        If Not @error Then
            $str = StringTrimRight($str, StringLen($str) - $pos + 1)
            Return $str
        EndIf
    EndIf
EndFunc
Edited by this-is-me
Who else would I be?
Link to comment
Share on other sites

Make your own.

$x="I want to go to school now."

$answer=StringBetween($x,"want to ", " now")
MsgBox(1,"Answer",$answer)

Func StringBetween($in,$_to, $_now)
If StringInStr($in,$_to)>0 and StringInStr($in,$_now)>0 Then
$out=StringTrimLeft($in,StringInStr($in,$_to)+StringLen($_to)-1)
$out=StringTrimRight($out,StringLen($out)-StringInStr($out,$_now))
Return $out
Else
    Return "Error"
EndIf
EndFunc

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Make your own.

$x="I want to go to school now."

$answer=StringBetween($x,"want to ", " now")
MsgBox(1,"Answer",$answer)

Func StringBetween($in,$_to, $_now)
If StringInStr($in,$_to)>0 and StringInStr($in,$_now)>0 Then
$out=StringTrimLeft($in,StringInStr($in,$_to)+StringLen($_to)-1)
$out=StringTrimRight($out,StringLen($out)-StringInStr($out,$_now))
Return $out
Else
    Return "Error"
EndIf
EndFunc

<{POST_SNAPBACK}>

Like I said "somebody is doing it"...

Someone fast, like Scriptkitty. :)

EDIT: typo

Edited by josbe
Link to comment
Share on other sites

Alright well I've been trying for a long time lol.

I have the text

<Username> :+: (S.### .... other text

And i want to retrieve the number and read that numbers file line. I don't know what to set x as

Edited by the_lord_mephy
My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]
Link to comment
Share on other sites

Guest BL@(K-R34P3R

Change it to an if statement, for all the answers to the trivia questions you are cheating on! LoL. Just make an in If then statement for each answer, then use the above scripts to make it work. Good luck.

Link to comment
Share on other sites

Guest BL@(K-R34P3R

What he means is that he has a chat client...

What shows up on the screen is <Username> :+: (S.### etc...)

He only wants to show the etc...

Thats why he made this topic.

Good point Valik.

Link to comment
Share on other sites

Black, you always know what my scripts are for lol. Valik, I am thinking and just because I'm not an Uber Coder like you, it doesn't mean you have to put me down, Jeez.

(I'm asking for it :))

Larry,

I am in a channel on a Battle.net game. In the channel there is a bot that says scrambled words in the following format. (Username is the account name of the bot pretend the word is abhor):

<Username> :+: (S.Number -> ahrob

The Number is the number of the word that is being scrambled. (Which is read from a file in the format):

Word1

Word2

Word3

Word4

Word5

Word6

Word7

etc.

The Number changes depending on the words location in the file.

What I want to do is have the bot Find the number of the question and send the answer.

My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]
Link to comment
Share on other sites

$x="I want to take you password LeetDawg#78321!"
; or might try $x=$line  if useing this in some filereadline()

$answer=StringBetween($x,"#", "!")
; or $answer=Number(StringBetween($x,"#", "!"))
MsgBox(1,"Answer",$answer)

Func StringBetween($in,$_to, $_now)
If StringInStr($in,$_to)>0 and StringInStr($in,$_now)>0 Then
$out=StringTrimLeft($in,StringInStr($in,$_to)+StringLen($_to)-1)
$out=StringTrimRight($out,StringLen($out)-StringInStr($out,$_now)+1)
Return $out
Else
    Return "Error"
EndIf
EndFunc

now you should research FileReadLine and such things, maybe you can read the file and when it finds a number instead of "Error" you can have it mark down the line number and the number it returned.

.... any resemblance to actually understanding what was said in:

Alright well I've been trying for a long time lol.

I have the text

<Username> :+: (S.###  .... other text

And i want to retrieve the number and read that numbers file line. I don't know what to set x as

is purely coincidental! Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Larry,

<Username> :+: (S.Number -> ahrob Would only apply if the word was abhor. If the word was glass it would look like this

<Username> :+: (S.Number -> lsgsa

Or something similar.

The Number is the number is declared by the word (that is being scrambled)'s place in the word file. What the scramble bot does is, it has a list of words in a .dat file. that looks like the following:

Word1

Word2

Word3

Word4

Word5

Word6

Word7

etc.

It selects a word at random, mixes up the letters, and sends that text in the channel. The other people in the channel need to unscramble that word and enter it. I'm trying to make a bot that does that automatically just for fun. If abhor was the 153rd word in the .dat file, the bot would Send this:

<Username> :+: (S.153 -> ahrob

My bot will look at the string in between ":+: (S." and " ". (returning the number 153) it would then execute

$word = FileReadLine("allwords.dat", "153")

Send($word)

Hopefully that's a little easier to understand.

Thanks for your patience.

@Valik

I don't take anything said to me on the computer offensively.

My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]
Link to comment
Share on other sites

Ok, doesn't really matter much. If you can read the text in some way, just set it to read the text and then use any of the function given here pretty much.

You may want to make it a number. Say use Larry's code:

$string = "<Username> :+: (S.153 -> ahrob"
$num = number(stringbetween($string,":+: (S."," ->")); slight modification
$word = FileReadLine("allwords.dat", $num)
Send($word)
MsgBox(4096,$word,$num")

Func stringbetween($str, $start, $end)
   $pos = StringInStr($str, $start)
   If Not @error Then
       $str = StringTrimLeft($str, $pos + StringLen($start) - 1)
       $pos = StringInStr($str, $end)
       If Not @error Then
           $str = StringTrimRight($str, StringLen($str) - $pos + 1)
           Return $str
       EndIf
   EndIf
EndFunc
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Yeah, I can get that that is a beautiful code. However, I don't know how to get a correct value for $string. I want it to update everytime the bot sends a new scrambled word.

My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]
Link to comment
Share on other sites

Yeah, I can get that that is a beautiful code. However, I don't know how to get a correct value for $string. I want it to update everytime the bot sends a new scrambled word.

<{POST_SNAPBACK}>

so you dont have the string ?

Alright well I've been trying for a long time lol.

I have the text

<Username> :+: (S.### .... other text

And i want to retrieve the number and read that numbers file line. I don't know what to set x as

so you do have the string!

I got this part of the question!!!

remember the old (old old ) games where in order to start the game you had

to answer a question like this:

enter the 5th word on page 6 of the manual

well, his number is the nth record on a file.

( here's some code to be used for a useless game)

$number= StringMid ( $line,(StringInStr($line,"(S.")+3),3) ; the number is always 3rd character on the line

(of course copy Larry's code which has enough error checking to be used in an airport and put it to good use, business use that is.)

to get $line you could :

WinWaitActive("Untitled - Notepad") ;works for notepad

$lines = WinGetText("Untitled - Notepad","") ;and it came from Help file

$linearray=StringSplit ($lines,@LF)

$line=$linearray[$linearray[0]-2] ;play with the index -3 ?

MsgBox(0, "line read was:"&$linearray[0], $line)

but of course there is the 64kb limit so you would have to make sure the lines that scroll over the top are deleted and I did a minus 2 on the array index in case the program you are using keeps an empty line at the end of the window

I figure this code will at least make others post so I didnt put any effort into it

(I have no shame on my copy/paste abilities )

P.S. I find myself reading this forum every single night just to enjoy the nutty replies to the even nuttiest (can you say jiffy ) questions :)

from scriptkitty trying to teach people how to fish

to valik's "are you stupid or just plain mental" comments

and of course the questions " I need a mouse left 100 and I need it NOW"

every one makes autoit3 even better.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...