split string by "." (1 Viewer)

cpampas

Registered User.
Local time
Today, 00:05
Joined
Jul 23, 2012
Messages
218
I ve been trying this for hours with no results, I wonder if someone can give me a hand.
Ihave a string:
str=" On Monday, 13th Nov 2023, Baxter International Inc stock price gained 2.71%, going from $32.82 to $33.71. Volume increased on the last day and 5 million more shares were traded than the day before ($305.06 million in total), posing a positive technical sign. According to the trend, it is expected for the stock to fall -25.15% over the next 3 months and hold a price within $20.82 and $25.12" into this :On Monday, 13th Nov 2023, Baxter International Inc stock price gained 2.71%, going from $32.82 to $33.71.
Volume increased on the last day and 5 million more shares were traded than the day before ($305.06 million in total), posing a positive technical sign.
According to the trend, it is expected for the stock to fall -25.15% over the next 3 months and hold a price within $20.82 and $25.12"

i want to split the text by "." , except in those cases where "." is a decimal separator, in this case the result in a msgbox would be :

On Monday, 13th Nov 2023, Baxter International Inc stock price gained 2.71%, going from $32.82 to $33.71.
Volume increased on the last day and 5 million more shares were traded than the day before ($305.06 million in total), posing a positive technical sign.
According to the trend, it is expected for the stock to fall -25.15% over the next 3 months and hold a price within $20.82 and $25.12"

I tried split by ".", but i dont see how to exclude the split in case of decimal numbers.
An ideas ?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:05
Joined
Oct 29, 2018
Messages
21,473
If your string contains it, can you split using carriage returns instead?
 

plog

Banishment Pending
Local time
Today, 02:05
Joined
May 11, 2011
Messages
11,646
I don't think you should exclude decimals but instead find them after the split and reassemble them.

split your string into an array by "." (arraySplit)
make another empty array (arrayFinal)
iterate over arraySplit array putting the first item into the first item of arrayFinal
then for every other item of arraySplit test it to if it starts with a number, if so extract the number and append it to the prior item in arrayFinal
then put the rest into a new item in arrayFinal

arrayFinal now contains what you want
 

MarkK

bit cruncher
Local time
Today, 00:05
Joined
Mar 17, 2004
Messages
8,181
You can split on more than one character. Try splitting on ". " None of the numeric values have a space after the period.
 

cpampas

Registered User.
Local time
Today, 00:05
Joined
Jul 23, 2012
Messages
218
Thank you all for you kind help
I followed Mark's idea . genious ! It works like a charm
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 08:05
Joined
Sep 12, 2006
Messages
15,656
Assuming there is always a space after a genuine full stop, you can can split by ". ", which would ignore well formed numbers.

I see @MarkK already suggested that, and it worked.
 

Users who are viewing this thread

Top Bottom