Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Split String
#1
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
#2
Macro Macro2342
Code:
Copy      Help
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]
#3
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!
#4
Macro Macro2342
Code:
Copy      Help
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]


Forum Jump:


Users browsing this thread: 1 Guest(s)