Jump to content

stringsplit anywhere with more than 2 consecutive spaces?


Recommended Posts

I need to split a string that might look something like this:

sectionone _three spaces_ section two _Ten spaces_ this is is section three _five spaces_ sectionfour

Sorry about the way I had to write that, the board was cleaning extra spaces out of my sentence.

Does anybody know a good way to achieve this?

Thanks!

Link to comment
Share on other sites

I need to split a string that might look something like this:

sectionone _three spaces_ section two _Ten spaces_ this is is section three _five spaces_ sectionfour

Sorry about the way I had to write that, the board was cleaning extra spaces out of my sentence.

Does anybody know a good way to achieve this?

Thanks!

Try this:

$TEXT should be "sectionone _three spaces_ section two _Ten spaces_ this is is section three _five spaces_ sectionfour"

$StripWS = StringStripWS($TEXT,4)
$DATA = StringSplit($StripWS," ")

When the words fail... music speaks.

Link to comment
Share on other sites

#include <array.au3>
$string = "section one   section two          this is is section three     section four"
$string = StringRegExpReplace($string,"\h{3,}","¬")
$array = StringSplit($string,"¬")
_ArrayDisplay($array)

:P

Edited by andybiochem
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

Thanks a TON guys! Fast reply! Now I will have to sit down and try to break down and understand what yours is doing andybiochem :P

Here's an explanation:

;----- this include allows us to view the array we're creating
#include <array.au3>

;----- this is the string we want to test
$string = "section one   section two          this is is section three     section four"

;----- in Regular Expressions "\h{3,}" means... "a horizontal whitespace, 3 times or more"
;----- each time a match for this is found it is replaced with "¬"
$string = StringRegExpReplace($string,"\h{3,}","¬")

;----- now split the string wherever there is a "¬"
$array = StringSplit($string,"¬")

;----- display the array
_ArrayDisplay($array)
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...