Sign in to follow this  
Followers 0
chachew

StringTrimRight returns no data

21 posts in this topic

#1 ·  Posted (edited)

I am pulling a version number from an embedded HTML window in an exe. Im trying to remove the last "." from the version number with StringTrimRight, but im having a problem.

#Include <IE.au3>
#Include <string.au3>
 
 
$oIE=_IEAttach("App Setup","Embedded",1)  ;attach to the application, the text is embedded HTML
$var=_IEBodyReadHTML($oIE)
$read=_StringBetween($var,"App ","<p>")
MsgBox(0,"",$read[0])
$trim=StringTrimRight($read,1)
MsgBox(0,"",$trim)

First Msgbox returns: 9.50.4.0. i want to trim the LAST "." from the number

Second Msgbox returns no text...what am i missing??

Edited by chachew

Share this post


Link to post
Share on other sites



$read is an array, you can't use a string function on an array, you need an array function such as _ArrayTrim, or use StringTrimRight($read[0], 1) instead.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

When i use StringTrimRight($read[0],1) i get the same result as MsgBox 1

If i use $trim=_ArrayTrim($read,1,1,0,0) then i get a result of "1"

If i use $trim=_ArrayTrim($read[0],1,1,0,0) then i get a result of "0"

Share this post


Link to post
Share on other sites

use _ArrayToString() to turn it into a string then use that variable in the StringTrimRight()


[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

use _ArrayToString() to turn it into a string then use that variable in the StringTrimRight()

Thought this was going to work...but i get the same results for both variables :graduated:

$oIE=_IEAttach("App Setup","Embedded",1)  ;attach to the application, the text is embedded HTML
$var=_IEBodyReadHTML($oIE)
$read=_StringBetween($var,"App ","<p>")
$read2=_ArrayToString($read)
MsgBox(0,"",$read[0])
$trim=StringTrimRight($read2,1)
MsgBox(0,"",$trim)
Edited by chachew

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

it may have been because you didnt have #include <Array.au3> at the top maby ;)

i did this and it worked

#include <Array.au3>
Dim $read[3] = ["10.", "20.", "30."]
$read2=_ArrayToString($read, "")
MsgBox(0,"",$read2)
$trim=StringTrimRight($read2,1)
MsgBox(0,"",$trim)

Edit: Problem Solved :graduated: it was part of the syntax i forgot about

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites

Are you 100% sure that the last character in that string is "."? If there's a space after it, you're deleting the space. Try using StringStripWS($Read[0], 2) just before you use the StringTrimRight line.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

it may have been because you didnt have #include <Array.au3> at the top maby ;)

i did this and it worked

#include <Array.au3>
Dim $read[3] = ["10.", "20.", "30."]
$read2=_ArrayToString($read, "")
MsgBox(0,"",$read2)
$trim=StringTrimRight($read2,1)
MsgBox(0,"",$trim)

Edit: Problem Solved :graduated: it was part of the syntax i forgot about

Yes i have #include <Array.au3>

Share this post


Link to post
Share on other sites

Are you 100% sure that the last character in that string is "."? If there's a space after it, you're deleting the space. Try using StringStripWS($Read[0], 2) just before you use the StringTrimRight line.

Tried this and same result...damnit :graduated:

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

chachew,

I would start by testing some return values after the function calls.

_arraydisplay() is also handy for quickly displaying an array

Kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

When i use StringTrimRight($read[0],1) i get the same result as MsgBox 1

If i use $trim=_ArrayTrim($read,1,1,0,0) then i get a result of "1"

If i use $trim=_ArrayTrim($read[0],1,1,0,0) then i get a result of "0"

What did you get in the array $read when you ran the first command? $trim is only going to be 1 or 0, the array is passed ByRef to the _ArrayTrim function. Try using a msgbox after the _ArrayTrim function to see what's in $read[0], something like this:

#include <Array.au3>
$read=_StringBetween($var,"App ","<p>")
MsgBox(0,"",$read[0])
_ArrayTrim($read, 1,1)
Msgbox(64, "", "|" & $read[0] & "|") ; I added the 2 "|" to make sure that the last and first characters are where you think they are

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

What did you get in the array $read when you ran the first command? $trim is only going to be 1 or 0, the array is passed ByRef to the _ArrayTrim function. Try using a msgbox after the _ArrayTrim function to see what's in $read[0], something like this:

#include <Array.au3>
$read=_StringBetween($var,"App ","<p>")
MsgBox(0,"",$read[0])
_ArrayTrim($read, 1,1)
Msgbox(64, "", "|" & $read[0] & "|") ; I added the 2 "|" to make sure that the last and first characters are where you think they are

With this suggestion i get the image below..

post-62902-0-26810500-1318537511_thumb.j

Share this post


Link to post
Share on other sites

With this suggestion i get the image below..

That tells me that there's something after the number that's not displaying in the msgbox,probably a CR or LF or 2. Try putting a StringStripWS($Read[0], 8) in there just before the first MsgBox, and see if it returns the same.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

That tells me that there's something after the number that's not displaying in the msgbox,probably a CR or LF or 2. Try putting a StringStripWS($Read[0], 8) in there just before the first MsgBox, and see if it returns the same.

Arrrgggg...still happens

$read=_StringBetween($var,"App ","<p>")
StringStripWS($Read[0], 8)
MsgBox(0,"",$read[0])
_ArrayTrim($read, 1,1)
Msgbox(64, "", "|" & $read[0] & "|")
Edited by chachew

Share this post


Link to post
Share on other sites

chachew,

At some point we are going to need to see this HTML source!!!

Kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Arrrgggg...still happens

$read=_StringBetween($var,"App ","<p>")
StringStripWS($Read[0], 8)
MsgBox(0,"",$read[0])
_ArrayTrim($read, 1,1)
Msgbox(64, "", "|" & $read[0] & "|")

You need to start reading the help file a lot better, you have to assign the return of StringStripWS to a variable, try it using $read[0] = StringStripWS($Read[0], 8) ; you could substitute the 8 with 2 to just strip trailing WS instead of all of it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

chachew,

At some point we are going to need to see this HTML source!!!

Kylomas

The html is embedded in the exe so here is the actuall HTML itself:

<html>
<font face="Arial, Helvetica, Geneva">Welcome to the installer for App 9.50.4.0.
<p>
<b><font color='red'>Please disconnect any scanners and connect any printers or cameras to your system before continuing.</font></b>
<p>
<font size=-2">
It is strongly recommended that you exit all Windows programs before continuing with this installation.  
<p>
This installation will shut down any internet explorer windows that may be running before installation
<p>
If you have any other programs running, please click Cancel, close the programs, and run this setup again.
<p>
Otherwise, click Next to continue.</font></font>
<//html>

Share this post


Link to post
Share on other sites

You need to start reading the help file a lot better, you have to assign the return of StringStripWS to a variable, try it using $read[0] = StringStripWS($Read[0], 8) ; you could substitute the 8 with 2 to just strip trailing WS instead of all of it.

Sweet, that works, now..i do see now where StringStripWS assigns to a variable :graduated: This is now the working code!

#Include <IE.au3>
#Include <string.au3>
#Include <array.au3>
 
 
$oIE=_IEAttach("App Setup","Embedded",1)  ;attach to the application, the text is embedded HTML
$var=_IEBodyReadHTML($oIE)
$read=_StringBetween($var,"App ","<p>")
$read[0]=StringStripWS($read[0], 8)
MsgBox(0,"",$read[0])
_ArrayTrim($read, 1,1)
Msgbox(0, "",$read[0])

Share this post


Link to post
Share on other sites

Thanks for all the help Guys

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