Sign in to follow this  
Followers 0
danpaul23

string question

12 posts in this topic

Thanks for everyone who has helped me so far, my apologies if my use of terms is off or if I'm not clear. Please correct me if I'm wrong, I'm really trying to learn.

I'm trying to create a string that I'm pulling from a web page. I can create the string for the constant part but I'm not sure hot to include the variable at the end.

This is the basic form of the string:

"this item costs X"

X is the variable that I want to include. Also, X is a price, so it's a decimal number and could be a different number each time. I.e. .01, 10,000.01, etc.

Share this post


Link to post
Share on other sites



Or, if you like the sprintf way, use StringFormat.

$Var1 = 10000
$FinalString = StringFormat ("this item costs %d", $Var1)

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Share this post


Link to post
Share on other sites

$var1 = "this item costs "
$Var2 = 1
$var3 = $var1 & $var2

Sorry, I guess I wasn't making myself clear. In the case of my program, $var1 is a constant that the program will search the web page for, after finding that variable I want the program to create a new variable for the number directly after $var1.

Share this post


Link to post
Share on other sites

Sorry, I guess I wasn't making myself clear. In the case of my program, $var1 is a constant that the program will search the web page for, after finding that variable I want the program to create a new variable for the number directly after $var1.

Why would you do that? Hhow will you know witch variable you have created and have access to?

I know you can do this in several scripting languages. In autoit there is no "nice" way to do it. But you can try:

Assign ( "varname", "data" [, flag] )

Share this post


Link to post
Share on other sites

; $szHTML is the web page source

$Var1 = "pie" ; The constant
$Var2 = StringInStr ($szHTML, $Var1)

If $Var2 <> 0 Then
   $Var3 = StringTrimLeft ($szHTML, $Var2) ; Var2 contains the place of the constant in the page source, so we cut what's before it.
   $Var3 = StringTrimRight ($Var3, 10)
EndIf


[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Share this post


Link to post
Share on other sites

Or, if you like the sprintf way, use StringFormat.

$Var1 = 10000
$FinalString = StringFormat ("this item costs %d", $Var1)
Thanks for your response but I was dumb and didn't make myself clear when I posted my initial question. It isn't me who is pulling the information from the page but my program. I can get the program to find the constant ("this item costs $") but I want to create a variable for the number which follows the "this item costs $".

Hope that's clear. Thanks again.

Share this post


Link to post
Share on other sites

Why would you do that? Hhow will you know witch variable you have created and have access to?

I know you can do this in several scripting languages. In autoit there is no "nice" way to do it. But you can try:

Assign ( "varname", "data" [, flag] )
It's just a temporary variable which the program will use to make a decision. Thanks for your response. I'm not quite sure about the script you sent, I'm just getting familiar with the language (this is my 4th day of writing script, in any language) but I'll peruse the help file and try to figure it out. Thanks again.

Share this post


Link to post
Share on other sites

; $szHTML is the web page source

$Var1 = "pie" ; The constant
$Var2 = StringInStr ($szHTML, $Var1)

If $Var2 <> 0 Then
   $Var3 = StringTrimLeft ($szHTML, $Var2) ; Var2 contains the place of the constant in the page source, so we cut what's before it.
   $Var3 = StringTrimRight ($Var3, 10)
EndIf
Thanks, I'll try it out.

Share this post


Link to post
Share on other sites

You should use StringRegExp and the array returned from it rather than creating variables on the fly.

Thanks, I was actually checking that out this AM before Dale posted some script that I've been trying to pick my way through since.

I was about to post a question about it.

Share this post


Link to post
Share on other sites

If you don't know regexp from another language (perl, sed, awk) and have problems with the pattern, just give us a hint and we will try to ease the burden without messing to much with your understanding of them. But you should post samples of the data you extract stuff from to get a reasonable answer.

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