Sign in to follow this  
Followers 0
PeteP

Getting strings to arrays from one string containing spaces

4 posts in this topic

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

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

I think this be easy using RegExp:

#include <Array.au3> ;Only for _ArrayDisplay :)

$MY_STRING = "color weight length width" & @TAB & "test string"
$sResult = StringRegExp($MY_STRING, "(\w+)", 3)

_ArrayDisplay($sResult)

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