Sign in to follow this  
Followers 0
strate

Eliminate Ws In A String?....

12 posts in this topic

I have a string that for example is like this "05/06/2006 05/07/2006 123456 54 n 4 6 6"

Each time the spaces in between each section of data is different. How can I make it so that stringsplit would work with it? I've tried for a day now and I just can't do it. I've been trying to use this but can't get it to match correctly.

$String = StringRegExpReplace("Where have all the flowers gone, long         time passing?", "\A", "G")
MsgBox(0, "Regular Exp[b][/b]ression Replace Test",$String)
_ArrayDisplay($String,'')

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites



StringStripWS

--------------------------------------------------------------------------------

Strips the white space in a string.

StringStripWS ( "string", flag )

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

StringStripWS

--------------------------------------------------------------------------------

Strips the white space in a string.

StringStripWS ( "string", flag )

8)

I'm sorry I guess I forgot to mention, I've tried that but it then makes a large string out of it. Nothing to use as a delimiter for the Stringsplit.

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I'm sorry I guess I forgot to mention, I've tried that but it then makes a large string out of it. Nothing to use as a delimiter for the Stringsplit.

$split = stringsplit($String, "") ; "" = nothing

for $x = 1 to $split[0]

if $split[$x] > " " then $new_string = $newstring & $split[$x] ; " " has a space in it

????

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

If my math is right, this will replace all consecutive spaces with a single space.

$t = "Where have all the flowers gone, long      time passing?"
Do
  $org = $t
  $t = StringReplace($t, "  ", " ");replace 2 with 1
Until $org = $t
MsgBox(0,"Result", $t)

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

$split = stringsplit($String, "") ; "" = nothing

for $x = 1 to $split[0]

if $split[$x] > " " then $new_string = $newstring & $split[$x] ; " " has a space in it

????

8)

This will return the string as one large string. Once again no delimiters.

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

If my math is right, this will replace all consecutive spaces with a single space.

$t = "Where have all the flowers gone, long      time passing?"
Do
  $org = $t
  $t = StringReplace($t, "  ", " ");replace 2 with 1
Until $org = $t
MsgBox(0,"Result", $t)
This works great!

Thank you both, Valuater and CyberSlug. Your help has been greatly apperciated.


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

these both work... cyber's is much shorter

$t = "Where have all the flowers gone, long      time passing?"
$newstring = ""
$space = 0
$split = StringSplit($t, "") 

For $x = 1 To $split[0]
    If $split[$x] = " " And $space = 0 Then
        $newstring = $newstring & $split[$x] 
        $space = 1
    EndIf
    If $split[$x] > " " Then
        $newstring = $newstring & $split[$x] 
        $space = 0
    EndIf
    
Next

Do
  $org = $t
  $t = StringReplace($t, "  ", " ");replace 2 with 1
Until $org = $t
MsgBox(0,"Result", $t & @CRLF & $newstring)

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

I finally found the regular expression you were originally seeking:

$t = "Where have all the flowers gone, long      time passing?"
$t = StringRegExpReplace ($t, "[:space:]+", " ")
MsgBox(0,"Result",$t)

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

I finally found the regular expression you were originally seeking:

$t = "Where have all the flowers gone, long      time passing?"
$t = StringRegExpReplace ($t, "[:space:]+", " ")
MsgBox(0,"Result",$t)
That's a much better way, but this also works (StringStripWS() that was suggested earlier) in the test that I did:
$t = "Where have all the flowers gone, long      time passing?"
$t = StringReplace($t, $t, StringStripWS($t, 7))
MsgBox(0,"Result",$t)

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

one line would have done it

$text = StringStripWS("Where have    all the     flowers gone, long      time passing?", 7)

MsgBox(0, "Stripped", $text)

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

one line would have done it

$text = StringStripWS("Where have    all the     flowers gone, long      time passing?", 7)

MsgBox(0, "Stripped", $text)

8)

Well if he's searching a string that's longer than what he has, don't know if that would work or keep the other spaces correctly, I guess I should have posted it like:
$StringToFind = "I have a simple question.  Where have all the flowers gone, long        time passing?"
$t = "Where have all the flowers gone, long      time passing?"
$t = StringReplace($StringToFind, $t, StringStripWS($t, 7))
MsgBox(0,"Result",$t)

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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