Hi All, how to remove blank line from a list by using script any idea? ,
regards
soma
Hi All, how to remove blank line from a list by using script any idea? ,
regards
soma
Subject: Remove blank line from list
Soma,
If the blank entry is at the beginning or end of the list, just use Trim.
If it is in the middle, you will have to create a new array excluding the blank entry. Something like this…
dim existingarray() as string
dim newarray() as string
-populate existingarray with the list
arraycounter%=0
forall a in existingarray
if a<>“” then
redim preserve newarray(0 to arraycounter%) as string
newarray(arraycounter%)=a
arraycounter%=arraycounter%+1
end forall
Then set the value of your list to newarray()
HTH
Mike
Subject: RE: Remove blank line from list
For those of us who have worked with the simplicity and power of the @formulas since 19… er. well, since before lotusscript came along, let’s just say, no need to date anyone unnecessarily… grin…
At any rate, compared to how much you can accomplish in @language sometimes in a few words, it can be hairpulling to realize the hoops you have to go through in script.
I needed a way to remove blank lines from a list / array, something you would do in a flash in formula language like this:
@ReplaceSubstring(mylist;@Newline;“”)
done. yeah, lunch on time today!
After hours of trying to do the same in script, I found Mike’s answer and it just about got me there, and I want to thank him retroactively for it.
Here it is just a tidge corrected for any scripting newbies :
Dim newarray() As String
Dim arraycounter As Integer 'Mike had omitted this
arraycounter%=0
Forall a In existingArray '*see footnote
If Len(a) > 2 Then '*see footnote
Redim Preserve newarray(0 To arraycounter%) As String
newarray(arraycounter%)=a
arraycounter%=arraycounter%+1
End If
End Forall
'take your newly-cleaned up array, and run with it. Sorry you didn’t get lunch today, grin.
as Mike pointed out, you must start with a pre-existing, already-populated array. And given that you are calling on this routine, ithat means it’s an array that irksomely has blank entries in it that are causing you grief later on in your script.
Mike had a<>“” but sometimes a line isn’t truly blank. It can have a tab or just some weirdness in it that though you can’t see it, it’s enough to make it not blank as far as the script is concerned, and therefore even though the line is blank for all intents and purposes, it maddeningly gets added into your supposedly nice clean new array. I got around that by just checking for a line length instead. I picked length of 2 for no particular good reason.
Thanks Mike, cheers!
Subject: RE: Remove blank line from list
THANK YOU RANDY!!! After searching for a day for the solution to this issue, I finally constructed the correct search, and found your post! This works beautifully.
Subject: RE: Remove blank line from list
I’m a bit afraid, that you won’t come back to this thread, now you found one solution, that’s backwards compatible with Notes 4 …
For the rare cases, where this is not too much of an issue, I might point your attention to what was added to LotusScript in Notes 6 (5 years ago). We do have stuff now like
ArrayGetIndex
ArrayReplace
ArrayAppend
ArrayUnique
Join
Split
to name a few. Much of what required painful looping in LotusScript 4 (that was the LotusScript version number in Notes 5) can now be done using one-liners as well. I didn’t mention Fulltrim yet (which was introduced in Notes 5, if I remember right), because I never found it to work exactly as advertised, but that might only be me.
Pay special attention to the power of combining join, text manipulation and split.
Talking about string manipulation: Here’s more LS stuff for people who love the power of formulas (like myself):
StrLeft
StrLeftBack
StrRight
StrRightBack
Have a look at the (pretty lousy) documentation and the formula programmer in you will feel at home instantly.
Subject: RE: Remove blank line from list
Hi Mike, Thanks for your immediate response, the problem is for example, if i have 3 values in a list, every value has blank line at the end of the value.i tried to trim not working, your sugegstion works if the value itself is blank. any idea
regds
soma
Subject: RE: Remove blank line from list
Soma,
What is the exact character at the end of each value (can you paste an example of your list?). If it a space then Trim ro Trim$ should work. If it is something else, then you might have to look at using Left$ to “chop off” the offending character (eg: Left$(value, len(value)-1)
Mike
Subject: RE: Remove blank line from list
Hi Mike, the content looks like this, just copy and paste it in notepad u see blank line.
Trim$ doesn’t work.
/tmp/finaltested/rep_/6/83def0847ecbe61565256fe4002be726/Japanese Life Ins Fitch 0803.pdf#/pubrep/batchdatatarget/6/83def0847ecbe61565256fe4002be726/Japanese Life Ins Fitch 0803.pdf
/tmp/finaltested/rep_/6/83def0847ecbe61565256fe4002be726/Japan Life - FitchRatings 4-8-04.pdf#/pubrep/batchdatatarget/6/83def0847ecbe61565256fe4002be726/Japan Life - FitchRatings 4-8-04.pdf
/tmp/finaltested/rep_/5/bb9a3b4a9809517965256fe4002be725/Japanese Life Ins Fitch 0803.pdf#/pubrep/batchdatatarget/5/bb9a3b4a9809517965256fe4002be725/Japanese Life Ins Fitch 0803.pdf
/tmp/finaltested/rep_/5/bb9a3b4a9809517965256fe4002be725/Japan Life - FitchRatings 4-8-04.pdf#/pubrep/batchdatatarget/5/bb9a3b4a9809517965256fe4002be725/Japan Life - FitchRatings 4-8-04.pdf
/tmp/finaltested/rep_/5/bb9a3b4a9809517965256fe4002be725/Japan Life Ins Mkt Pain.pdf#/pubrep/batchdatatarget/5/bb9a3b4a9809517965256fe4002be725/Japan Life Ins Mkt Pain.pdf
/tmp/finaltested/rep_/4/31bd6d8b98000aa465256fe4002be724/Japan Life - FitchRatings 4-8-04.pdf#/pubrep/batchdatatarget/4/31bd6d8b98000aa465256fe4002be724/Japan Life - FitchRatings 4-8-04.pdf
/tmp/finaltested/rep_/3/325a38bbf6ca906765256fe4002be723/Japanese Life Ins Fitch 0803.pdf#/pubrep/batchdatatarget/3/325a38bbf6ca906765256fe4002be723/Japanese Life Ins Fitch 0803.pdf
/tmp/finaltested/rep_/3/325a38bbf6ca906765256fe4002be723/Japan Life - FitchRatings 4-8-04.pdf#/pubrep/batchdatatarget/3/325a38bbf6ca906765256fe4002be723/Japan Life - FitchRatings 4-8-04.pdf
Subject: RE: Remove blank line from list
But in your first message you’ve asked about removing BLANK lines from array of strings… Mike has written the correct solution ![]()
Concerning you actual question:
forall item in extstingArray
item = fulltrim (item)
end forall
// wbr, rod
Subject: RE: Remove blank line from list
Hi Rodion, your suggestion solved my problem. thanks a lot.
regds
soma