split string by "."

cpampas

Registered User.
Local time
Yesterday, 23:13
Joined
Jul 23, 2012
Messages
221
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 ?
 
If your string contains it, can you split using carriage returns instead?
 
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
 
You can split on more than one character. Try splitting on ". " None of the numeric values have a space after the period.
 
Thank you all for you kind help
I followed Mark's idea . genious ! It works like a charm
 
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

Back
Top Bottom