Posts: 97
Threads: 48
Joined: Sep 2010
Hello,
I have a text in a string, like 400 characters, i want this splitted in 3 strings of 150 characters. So i have finally 2 strings of 150 characters and 1 of 100.
And if it's possible, the split must be done before the whole word (a space character) so the length of a string can vary but never more than 150 characters.
i don't know how to do this, is somebody here who can help me out?
Thanks In Advance
Sonic
Posts: 12,147
Threads: 143
Joined: Dec 2002
Macro
Macro2342
out
str s=
;Hello,
;
;I have a text in a string, like 400 characters, i want this splitted in 3 strings of 150 characters. So i have finally 2 strings of 150 characters and 1 of 100.
;And if it's possible, the split must be done before the whole word (a space character) so the length of a string can vary but never more than 150 characters.
;
;i don't know how to do this, is somebody here who can help me out?
ARRAY(str) a
;if(!findrx(s "(?s)(.{1,150}\b)" 0 4 a)) end "failed"
if(!findrx(s "(?s)(.{1,150})(?:\s+|$)" 0 4 a)) end "failed"
int i
for i 0 a.len
,out a[1 i].len
,out a[1 i]
Posts: 97
Threads: 48
Joined: Sep 2010
Hi,
Another question about this, what if the length is variable and i have the variable calculated in 'x' can i use this to set the maximum length?
so like in the regex :
if(!findrx(value "(?s).{1,150}\b" 0 4 a)) end "failed"
where the 150 stands now, a variable ? Is this possible?
Many thanks in advance!
Posts: 12,147
Threads: 143
Joined: Dec 2002
Macro
Macro2342
out
str s=
;Hello,
;
;I have a text in a string, like 400 characters, i want this splitted in 3 strings of 150 characters. So i have finally 2 strings of 150 characters and 1 of 100.
;And if it's possible, the split must be done before the whole word (a space character) so the length of a string can vary but never more than 150 characters.
;
;i don't know how to do this, is somebody here who can help me out?
int x=150
ARRAY(str) a
;if(!findrx(s _s.format("(?s)(.{1,%i})(?:\s+|$)" x) 0 4 a)) end "failed"
if(!findrx(s F"(?s)(.{{1,{x}})(?:\s+|$)" 0 4 a)) end "failed"
int i
for i 0 a.len
,out a[1 i].len
,out a[1 i]