Jump to content

Getting strings to arrays from one string containing spaces


PeteP
 Share

Recommended Posts

Hello,

I have one string with several information elements containing spaces or tabs and I would like to pick up all elements... But I just can't really figure out the best way to do it...

For example I have $MY_STRING containing following data: "color weight length width"

All those are separated with unknown number of spaces or even tabs.. So how can I pick up each of those elements in arrays??

Thanks

-Pete

Link to comment
Share on other sites

$information = "bla 2 xD bla ... bla"
$information = StringSplit($inforamtion, " ")

$information will return an array containing :

[0] => 6 (6 items)

[1] => "bla" ; first item

[2] => "2" ; second item

.... ;and so on

[6] => "bla" ; until the last one

[center]I want to change the world ...., but I don't have the source code xD[/center]

Link to comment
Share on other sites

Hello,

I have one string with several information elements containing spaces or tabs and I would like to pick up all elements... But I just can't really figure out the best way to do it...

For example I have $MY_STRING containing following data: "color weight length width"

All those are separated with unknown number of spaces or even tabs.. So how can I pick up each of those elements in arrays??

Thanks

-Pete

First get rid of the tabs, then convert multiple spaces into one space then stringsplit.

$string = "color        weight          length    width"
$convert1 = StringReplace($string,Chr(9),'')
$convert2 = StringStripWS($convert1,4);strip double (or more) spaces between words
$arrayString = StringSplit($convert2,' ')
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...