Posts: 76
Threads: 37
Joined: Nov 2018
i have multi-line string that i want to remove the excess lines and just leave 1 double space. i have tried the findreplace("[] []" "[]". thinking it would remove double carriage and leave 1 but it removes ALL carriage returns/new lines. i want to leave 1 line space between strings
EXAMPLE
dog jump over the fence
the cat meows
look both ways before crossing
SHOULD BE...
dog jump over the fence
the cat meows
look both ways before crossing
Posts: 1,337
Threads: 61
Joined: Jul 2006
this works
s.findreplace("[][]" "[]")
str s=
;dog jump over the fence
;
;
;the cat meows
;
;
;look both ways before crossing
;
;;
out numlines(s)
s.findreplace("[][]" "[]")
out numlines(s)
out s
this doesn't
s.findreplace("[] []" "[]")
nor does
s.findreplace("[][]" "[]" 8)
Posts: 76
Threads: 37
Joined: Nov 2018
08-01-2020, 01:20 AM
(This post was last modified: 08-01-2020, 01:54 AM by ilcaa.)
thanks kevin. but this fails if the spacing or carriage returns isnt exactly 2 or less... my examples has 3 and 2, my real world has 3, 6, 4. carriage returns/new lines between strings....
out
str a
str s="one[][][][][][]two[][][][][]yes"
s.findreplace("[][]" "[]")
out s
,
Posts: 117
Threads: 5
Joined: Nov 2015
08-01-2020, 03:51 AM
(This post was last modified: 08-01-2020, 02:31 PM by Start_Learning.)
Try this function:
Function
TrimMultiBlankLines
;Reduce multi blank lines into one blank line only.
function str'text
str line
int emptyLineCount emptyLineExist
out
foreach line text
,line.trim()
,if (len(line) = 0)
,,emptyLineCount +=1
,,emptyLineExist = 1
,,if (emptyLineCount > 1)
,,,emptyLineExist = 0
,else
,,out line
,,emptyLineCount = 0
,if (emptyLineExist )
,,out ""
,,emptyLineExist = 0
Usage: TrimMultiBlankLines [string_text]
Posts: 1,337
Threads: 61
Joined: Jul 2006
08-01-2020, 06:51 AM
(This post was last modified: 08-01-2020, 08:48 AM by Kevin.)
replacerx using regular expressions would probably be best here
out
str s="one[][][][][][]two[][][][][]yes[][][][][][][][]No[][]End"
s.replacerx("[\r\n]+" "[][]")
out s