danpaul23 Posted January 12, 2007 Posted January 12, 2007 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.
Developers Jos Posted January 12, 2007 Developers Posted January 12, 2007 $var1 = "this item costs " $Var2 = 1 $var3 = $var1 & $var2 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
CoePSX Posted January 12, 2007 Posted January 12, 2007 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]
danpaul23 Posted January 12, 2007 Author Posted January 12, 2007 $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.
Uten Posted January 12, 2007 Posted January 12, 2007 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] ) Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
CoePSX Posted January 12, 2007 Posted January 12, 2007 ; $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]
danpaul23 Posted January 12, 2007 Author Posted January 12, 2007 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.
danpaul23 Posted January 12, 2007 Author Posted January 12, 2007 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.
danpaul23 Posted January 12, 2007 Author Posted January 12, 2007 ; $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.
Uten Posted January 13, 2007 Posted January 13, 2007 You should use StringRegExp and the array returned from it rather than creating variables on the fly. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
danpaul23 Posted January 13, 2007 Author Posted January 13, 2007 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.
Uten Posted January 13, 2007 Posted January 13, 2007 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. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now