Sign in to follow this  
Followers 0
WeMartiansAreFriendly

Split this string into 4

4 posts in this topic

I need to split up a string like this:

47.5% (.Word) Description (10527/13/4)

into 4 parts

so it would be turned it this

47.5% 
.Word 
Description 
10527/13/4

Im can't get into how to do this.. regular expressions? well heres my code.

Local $sStr, $a[4]
Local $sStringf = '47.5% (.Word) Description (10527/13/4)'

$sStr = StringStripWS($sStringf,3)
$a[0] = StringLeft($sStr, StringInStr($sStr,'(') -1)
$a[1] = StringLeft(StringMid($sStr, StringInStr($sStr,'(')),StringInStr($sStr,')'))
$a[2] = StringMid($sStr, StringInStr($sStr,'('))
$a[3] = StringRight($sStr, StringInStr($sStr,')',0,1))

MsgBox(0,$sStringf,$a[0] &@lf& $a[1] &@lf& $a[2] &@lf& $a[3])

#cs
want to return
47.5% 
.Word 
Description 
10527/13/4
#ce

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Why not just StringSplit at the spaces?

edit - And StringReplace, of course, to get rid of the brackets.

#include <array.au3>  ; just for arraydisplay

$str = StringReplace('47.5% (.Word) Description (10527/13/4)', '(', '')
$str = StringReplace($str, ')', '')
$ret = StringSplit($str, ' ')

_ArrayDisplay($ret)
Edited by xcal

Share this post


Link to post
Share on other sites

Why not just StringSplit at the spaces?

edit - And StringReplace, of course, to get rid of the brackets.

#include <array.au3>  ; just for arraydisplay

$str = StringReplace('47.5% (.Word) Description (10527/13/4)', '(', '')
$str = StringReplace($str, ')', '')
$ret = StringSplit($str, ' ')

_ArrayDisplay($ret)
I knew it was something so simple I was overlooking. :)

big thanks


Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites

Erg.. I ran into a problem, which now I remember why I didn't use stringsplit() :)

If the string contains more than one space in the second part it will output e.g. I forgot about that.

47.5% .Word cWord3 cWord2 cWord3 10527/13/4

47.5% 
.Word 
cWord3 
cWord2 
cWord3 
10527/13/4

I need

47.5% 
.Word 
cWord3 cWord2 cWord3 
10527/13/4

Any other ideas??


Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

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