Jump to content
Sign in to follow this  
senator

How to remove spaces from a file

Recommended Posts

senator

Hey all! So I have a .txt file and I want autoit to load the textfile and remove all the spaces and [tab] spaces (the long spaces).

Thanks in advance

Share this post


Link to post
Share on other sites
Melba23

senator,

Look at StringStripWS in the Help file.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
senator

I can't seem to get it to work.

Here's how my 'string' looks like:

text

text

text

text

text

text

text

..and so on..

And this line is supposed to write the string to a .txt file

FileWriteLine($path,StringStripCR($thestring))

The problem is it writes it without removing the spaces.

Share this post


Link to post
Share on other sites
cageman

FileWriteLine($path,StringStripWS(StringStripCR($thestring))) That should clear everything. Then you get texttexttexttext etc.

Share this post


Link to post
Share on other sites
senator

Thanks, before i try it out, is there any way to get it to "text,text,text,text" instead "texttexttext" ? Actually I'm sure there is a way lol

Edited by senator

Share this post


Link to post
Share on other sites
FireFox

@senator

StringReplace('texttexttext', 'tt', 't,t')

Cheers, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
senator

1. StringStripWS(StringStripCR($users) is not good, it needs a flag. What should i put there.

2. FireFox, that would only work if my string was full of "text"s. Its more like "text, somethingelse,anotherword..."

Share this post


Link to post
Share on other sites
Melba23

senator,

Get your text into an array - _FileReadToArray will do this for you. Then loop through the array:

; Just to have a test array for this example

$sString = "test    " & @CRLF & @CRLF & "test   "
$aArray = StringSplit($sString, @CRLF)

; Start here if you use _FileReadToArray

$sNewString = ""

For $i = 1 To $aArray[0]
    If StringLen($aArray[$i]) > 0 Then
        $sNewString &= StringStripWS($aArray[$i], 8) & ","
    EndIf
Next

ConsoleWrite($sNewString & @CRLF)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
senator

haha, finally I've got it to work!

Thanks very much to all of ya !

Share this post


Link to post
Share on other sites
antoine

Hi,

I'm not certain but try something like

StringReplace('texttexttext', @LF, '')

followed by

StringReplace('texttexttext', @LR, '')

for each line of your file.

regards,

Antoine

Share this post


Link to post
Share on other sites
senator

thanks for trying to help, but Melba23's method works perfectly.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.