31290

Removing Bunch of spaces

14 posts in this topic

Hi Everyone, 

I'm facing a small issue while trying to remove spaces at the end of lines contained in a temp file.

Indeed, I'm creating the list of uninstallable apps on my computer and display them in an edit box.

Here's the result:

2015-10-11_12-57-41.thumb.png.f60db6dee3

As you can see, all lines have bunch of spaces at their end.

I did try the StringStripWS function, the StringTrimLeft one... no one works... 

Here's the code I use:

Func f_ListApps()
GuiCtrlSetState ($g_AppList, $GUI_DISABLE)
RunWait(@ComSpec & ' /c ' & 'wmic /node:' & @Computername &' product get name > %temp%\model.txt' ,"", @SW_HIDE)
$file =(@TempDir & "/model.txt")
$fileread = FileRead($file)
GUICtrlCreateEdit($fileread, 5, 250, 395, 400)
FileDelete(@TempDir & "/model.txt")
EndFunc

Surely a dumbass question but few hairs remains on my head :)

Thanks :)


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites



How did you use StringStripWS? This function should be exactly what you are looking for.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Water :)

Indeed, this function will do the trick...

I tried:

$fileread= FileRead($file)
$filefile = StringStripWS ( $fileread, 2 )

And

$filefile = StringStripWS (ChrW(160) & $fileread & ChrW(160), 2 )

No successes :/


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

You are reading the whole file into one variable. Using StringStripWS on this variable will only remove white space from the last line.
Means:
Use FileReadToArray to read the file into an array, then loop through the array and use StringStripWS on every element.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Yuk, I don't like arrays :) 

Ok, I'll try that and give you an update.

Thanks water!

Edited by 31290

~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

It's not too complex:

#include <StringConstants.au3>
$aFileArray = FileReadToArray($file)
For $i = 0 To UBound($aFileArray, 1) - 1
    $aFileArray[$i] = StringStripWs($aFileArray[$i], $STR_STRIPTRAILING)
Next

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Ok, I understand the way and thanks for that.

But, when I display my edit box, I got a subscript error :blink:

Global $editBox = GUICtrlCreateEdit($aFileArray[$i], 5, 250, 395, 400)

 


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

You can't add an array to the edit control. Use:

Global $editBox = GUICtrlCreateEdit(_ArrayToString($aFileArray[$i], @CRLF), 5, 250, 395, 400)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

johnOne, 

Thanks for your input.

Yes, the array exists and is not empty.

 


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

water, I still have a subscript error :/

When displaying the array with _ArrayDisplay:

ezrg.thumb.png.e450dc3799ffa64ea58958c29

The array is not empty ^^

 

Edited by 31290

~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

My bad, should be:

Global $editBox = GUICtrlCreateEdit(_ArrayToString($aFileArray, @CRLF), 5, 250, 395, 400)

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Yeah water, 

This is now working as expected. Was looking to deal with the @error flag when I saw your answer.

 Thanks a lot again :)


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

:)

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

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

  • Similar Content

    • MuffinMan
      By MuffinMan
      I am trying to rebuild an old single signon script that has been giving us a bit of trouble lately.  I didn't write it and it was written in another script language.  If the target program is already open it will have the current user's last name as part of the window text, which I am trying to compare against the user name to see if I should just WinActivate or Process Close and start the program over.  I will be provided the username like "jones", or "smith" and the title check works fine for last names (with no spaces), but if the last name DOES contains spaces, say "Nom De Plume", then all I will be given as a username is "nomdeplume".  Is there any way (via a regex maybe) that I can still check the text on the screen and somehow ?  I have been reading about the Advanced (4) mode of WinTitleMatchMode, but it is over my head.  Any help is appreciated.  Here is a small reproducer script:
      Opt("WinTitleMatchMode", -1) Run("Notepad") WinWait("[CLASS:Notepad]", "", 10) Send ("Smith" & @CRLF & "Jones" & @CRLF & "Nom De Plume" & @CRLF) If WinExists("[CLASS:Notepad]", "jones") Then MsgBox(0,"FOUND","Found Jones") EndIf If WinExists("[CLASS:Notepad]", "nomdeplume") Then MsgBox(0,"FOUND","Found Nom De Plume") EndIf  
    • Simpel
      By Simpel
      Hi,
      I'm trying to create a console reader. All is working but I have a problem with the look. I want the line numbers with another backgroundcolor in silver. I made this with a small silver label. The edit control over the label has a transparent background.
      But if I start the prog then i can see how the line numbers wipe the silver background off. And if I click into the Edit then the silver label disappears completely.
      #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> #include <StaticConstants.au3> #include <GuiEdit.au3> Opt("GUIOnEventMode", 1) Global $g_iZaehler = 0 Global $g_hGUI = GUICreate("Console: StdoutRead" , 800, 800, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPCHILDREN, $WS_EX_ACCEPTFILES) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Global $text = GUICtrlCreateEdit("",10,30,780,760, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_READONLY + $ES_NOHIDESEL) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $g_LaZeilen = GUICtrlCreateLabel("Zeilen: " & StringFormat("% 5d", $g_iZaehler), 680, 10, 100, 9, $SS_LEFTNOWORDWRAP) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKSIZE) Global $g_hCbFreeze = GUICtrlCreateCheckbox("&Freeze", 13, 5, 90) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlCreateLabel("", 11, 31, 42, 758) ; soll die Ziffern andersfarbig hinterlegen GUICtrlSetBkColor(-1, $COLOR_SILVER) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) GUISetState(@SW_SHOW) Global $sText = StringFormat("% 5d", $g_iZaehler) & @CRLF _GUICtrlEdit_AppendText($text, $sText) While 1 Sleep(200) $g_iZaehler += 1 $sText = StringFormat("% 5d", $g_iZaehler) & @CRLF _GUICtrlEdit_AppendText($text, $sText) WEnd Func _Exit() Exit EndFunc Do you have any suggestions.
      Regards, Conrad
    • Chimp
      By Chimp
      Given an "Edit control" with Horizontal and Vertical scroll bars, setted with a monospace font,
      How can I know:
      1) the exact client area dimension (excluding the surface of the Vert and Horiz. scroll bars )
      2) the dimensions (in pixel or whatever) of the hidden portions of the "Edit control" that are on the right and/or on the left and/or over the top and/or below the bottom of the visible part?, that is:
      if the content of the Edit control is completly visible, then there are not hidden portions, while if the content of the control is biggher of the visible area, then there are hidden parts. How to know the dimensions of the not visible portions of the Edit control  on any given moment while I'm  scrolling vertically and/or horizzontaly or if I change the dimensions of the font as well?
      For example, when I set the Font dimension = 7, the whole text is visible, so the scrollbars are grayed out and parameters of the hidden parts should be all 0.
      Since I'm sure that my explanation in english is not clear, I post this short script to show in practice the question:
      Thanks for any suggestion.
      #include <GUIConstants.au3> HotKeySet("{ESC}", "End") Local $aData Local $Char = " 1 2 3 4 5 6 7 8" & @CRLF $Char &= "12345678901234567890123456789012345678901234567890123456789012345678901234567890" & @CRLF For $i = 3 To 22 $Char &= StringFormat('%02i', $i) & _StringReplicate(" ", 7) & "|" & _StringReplicate(" |", 7) & @CRLF Next Global $MyGui = GUICreate("", 600, 430) Global $hEdit1 = GUICtrlCreateEdit($Char, 0, 0, 500, 300, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_READONLY, $ES_MULTILINE)) GUICtrlSetFont(-1, 7, 0, 0, "Courier New") GUICtrlSetBkColor($hEdit1, 0xffffff) Local $idRadio1 = GUICtrlCreateRadio("Font size 7", 505, 10, 120, 20) Local $idRadio2 = GUICtrlCreateRadio("Font size 10", 505, 40, 120, 20) Local $idRadio3 = GUICtrlCreateRadio("Font size 12", 505, 70, 120, 20) Local $idRadio4 = GUICtrlCreateRadio("Font size 16", 505, 100, 120, 20) GUICtrlSetState($idRadio1, $GUI_CHECKED) GUICtrlCreateLabel("pixel hidden on the left : " & @CRLF & _ "pixel hidden on the right : " & @CRLF & _ "pixel hidden over the top : " & @CRLF & _ "pixel hidden below bottom : " & @CRLF & _ "Width of the edit : " & @CRLF & _ "Height of the edit : ", 5, 305, 400, 150) GUICtrlSetFont(-1, 12, 0, 0, "Courier New") Local $hParameters = GUICtrlCreateLabel("", 300, 305, 200, 150) GUICtrlSetFont(-1, 12, 0, 0, "Courier New") GUISetState() While 1 $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE End() Case $iMsg = $idRadio1 GUICtrlSetFont($hEdit1, 7, 0, 0, "Courier New") Case $iMsg = $idRadio2 GUICtrlSetFont($hEdit1, 10, 0, 0, "Courier New") Case $iMsg = $idRadio3 GUICtrlSetFont($hEdit1, 12, 0, 0, "Courier New") Case $iMsg = $idRadio4 GUICtrlSetFont($hEdit1, 16, 0, 0, "Courier New") EndSelect $aData = _CheckEdit($hEdit1) ; this should return actual parameters of the Edit <----- ??? how to get this data ??? GUICtrlSetData($hParameters, $aData[0] & @CRLF & $aData[1] & @CRLF & $aData[2] & @CRLF & $aData[3] & @CRLF & $aData[4] & @CRLF & $aData[5]) WEnd Func _CheckEdit($hEdit1) ; <----- ??? how to get this data about the passed Edit ??? Local $aData[6] $aData[0] = "???" ; Hidden pixels on the left $aData[1] = "???" ; Hidden pixels on the right $aData[2] = "???" ; Hidden pixels over the top $aData[3] = "???" ; Hidden pixels below bottom $aData[4] = "???" ; Width of the visible portion of the Edit (without scrollbar surface) $aData[5] = "???" ; Height of the visible portion of the Edit (without scrollbar surface) Return $aData EndFunc ;==>_CheckEdit ; returns one or more chars replicated n times ; Example: ConsoleWrite(_StringReplicate('*', 5) & @CRLF) Func _StringReplicate($sChars = "", $iRepeats = 0) $sChars = String($sChars) $iRepeats = Int(Abs(Number($iRepeats))) Return StringReplace(StringFormat('%' & $iRepeats & 's', ""), " ", $sChars) EndFunc ;==>_StringReplicate Func End() If WinActive("[ACTIVE]") = $MyGui Then Exit EndIf EndFunc ;==>End  
    • TheDcoder
      By TheDcoder
      Hello! I think the thread title is obvious enough , Here is my code:
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 290, 139, 192, 124) $Edit1 = GUICtrlCreateEdit("Test", 8, 8, 273, 121, $ES_READONLY) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
      Thanks in advance, TD
    • jsmcpn
      By jsmcpn
      Hello all!  I'm trying to make a little script that sends a message over TCP.  An example payload would be:
      MY_PAYLOAD#<ATTRS><ATTR><NAME>MAILSERVER</NAME><OPERATION>set_value(ServiceStatus)</OPERATION><VALUE><![CDATA["Not Running"]]></VALUE><TIMESTAMP>1349297031</TIMESTAMP></ATTR></ATTRS> Note how the payload contains special characters, and how the CDATA contains a SPACE (i.e.  "Not Running")
      My compiled AU3 script expects exactly two command line arguments:
      1) destination server/port expressed as 127.0.0.1:80
      2) the payload I want to send to my server application (which may have multiple ATTRs, this example only has one ATTR)
      MyApp.exe 127.0.0.1:80 "MY_PAYLOAD#<ATTRS><ATTR><NAME>MAILSERVER</NAME><OPERATION>set_value(ServiceStatus)</OPERATION><VALUE><![CDATA["Not Running"]]></VALUE><TIMESTAMP>1349297031</TIMESTAMP></ATTR></ATTRS>"  
      My problems (plural) are with parsing of the second argument:
      1)  If I don't wrap second argument in double-quotes, then Windows bails out before even launching EXE with "< was unexpected at this time"
      2)  If I DO wrap second argument in double-quotes, then two problems can arise when my EXE parses the arguments:
                   aa) The double-quotes are stripped from the CDATA value. ["Running"] is stored in the array as [Running]
                   bb) If CDATA value DOES have a space, such as ["Not Running"], then I get an extra unwanted $CmdLine[3] because the SPACE between Not and Running is treated as a separator.  My second argument is thus split into two separate arguments, [2] and [3] instead of being treated as one arg stored in [2]
                              cc) Additionally, my script exits because it has an "IF $CmdLine[0] <>2 THEN Exit (1)" to validate the command line args.
      I've tried launching the EXE with the second argument wrapped and escaped in a multitude of ways.  Double double-quotes, triple double-quotes, single-quotes on the outside with double-quotes inside (i.e.  '"ETC"'), starting the second arg with a caret (i.e. ^"ETC") and one of three things happens:
      1) "< was unexpected at this time"
      2) my CDATA value is stripped of its double-quotes
      3) my payload argument gets split at the space in the CDATA value and the script bails out due to the unexpected 3rd argument.
       
      Any ideas?  How can I preserve the second argument literally, including all special characters, quotes and spaces?
      I tried adding some string manipulation code to grab the 2nd argument from $CmdLineRaw and it works (preserves the "Not Running" with quotes), but my number of arguments is still 3 instead of 2 if there is a space in the CDATA value.
       
      Any assistance would be greatly appreciated!