Removing first empty line in a field

Hi.
I've created a script to clean-up and format a block of text with multiple carriage returns within it. However, there is an empty line at the top that I just can't get rid of and its not padding.

How can I delete the first carriage return in the field to rid me of that extra empty line?

Appreciated, Karlos.

You may use the Right() function which returns the rightmost n characters from a tex, n being set to the length of the text minus one. Say the text is inside variable $myText, you would type:

Set Variable [ $myText ; Value : Right ( $myText ; Lenght ( $myText ) - 1 ) ) ]

Thank you planteg.
I used it in 'set field' and it clean-up my text perfectly!

I don't understand how it worked though. I understand that it takes the furthest right character but why from the first line and why not from the last, I mean its reference is the whole block of text so why did it grab the furthest right from the first line and not the last?

Appreciated, Karlos.

Right() returns a certain number of characters that are at the right of a text. Suppose your text is 30 characters long, and you use Right ( myText ; 27 ): then the 27 characters at the right of the text will be returned, and the 3 first characters will be left out. One other way to see it is to count from the right (last character) 27 characters and return these.

There is also Left () function that will return the n first charcutiers from the left.

These two functions are universal, all languages implements them. Another function is Substring (), or Mid (), depending on the language.

Thanks for the reply but I still don't understand.

Say I had a field called MyText with two lines in it separated with a carriage return...

12345
6789

Since the formula's only reference is 'MyText' I would have thought right(MyText;1) would result in the value of 9, why would it result in the value of 5 as with your solution? which took the far right character [carriage return] of the first line.

Again, our solution to my problem targeted the far right character of the first line and I don't understand why, I would have thought with only a reference of MyText it would have grabbed the far right of the last line.

With that in mind I was attempting to isolate the far right of the first line with...

GetValue(MyText; 1)`

Appreciated, Karl.

Ok, I get your question.

What you see, that is the two lines, is the way the contents of myText is displayed. But the contents of myString is simply a string of characters, a one dimension array, that contains:

12345¶6789

See the character between 5 and 6 ? That is what's called the pilcrow, a character used to represent a paragraph mark. So myString contains 10 characters, not 9. When the string is displayed, ¶ is replaced on the screen bay a carriage return followed by newline.

Right() does see ¶ as a character like the others, this why Right ( $myString) ; 1 ) returns 9, which is the last character in the string.

Now suppose that you have a ¶ right at the beginning of the string:


12345¶
6789

(the pilcrow result is shown here). If you use Right ( $mySTring ; Length ( $myString ) - 1 ), then you ask everything in $myString starting from the right, but the 1st character.

Does that make sense ?

Right () and Left () work on [charcuter :disappointed:] character strings, not lines.

1 Like

I must admit it took a while for the penny to drop but then I got it with your words "but the 1st character."

The whole text string is included as 'right' because of the 'length' element, and as it is all incorporated in the right() it has to take from the left [start] when you subtract anything from it.

I probably didn't explain that very well but I've got it. I have one last issue which I hope to post as a new topic tomorrow then my little 'clean-up and formatting field' will be complete.

Thanks, very appreciated, Karlos.

Sometimes, it's useful to transform the text into something expected before you begin parsing. There are many opinions about how to do this best, but here is one approach.

I broke this down into a let statement, so you can see what it does. There are also Custom Functions out there that will do the same thing for you, just using your text as input and giving you back clean, trimmed text.

Let ( 

[

	myText = "¶12345¶6789¶" ; 
	subText = Substitute ( myText ; [ " " ; "|" ] ; [ "¶" ; " " ] ) ; 
	trimText = Trim ( subText ) ; 
	finalText = Substitute ( trimText ; [ " " ; "¶" ] ; [ "|" ; " " ] )

] ; 

	List ( 
		valueCount ( myText ) ; 
		PatternCount ( subText ; " " ) ; 
		PatternCount ( trimText ; " " ) ; 
		valueCount ( finalText ) 

	)

)

In use, obviously, you aren't going list out everything. So just replace that entire chunk where List is, with finalText.

Let ( 

[

	myText = "¶12345¶6789¶" ; 
	subText = Substitute ( myText ; [ " " ; "|" ] ; [ "¶" ; " " ] ) ; 
	trimText = Trim ( subText ) ; 
	finalText = Substitute ( trimText ; [ " " ; "¶" ] ; [ "|" ; " " ] )

] ; 

	finalText

)

In a script, make this a Set Variable. Then in the next step, continue on with whatever you were doing and use this new variable as the input.

3 Likes

This sounds like the kind of setup where you accumulate content in a field by adding to existing content whatever new material is added. Typically I use this kind of thing in, say, a notes field where I add current content at the top of existing content. My approach to this is to make a conditional calc to check whether there is existing content, thus:
Let (
[
newText = Self
; existingText = nameOfFieldHere
; result = If ( IsEmpty ( existingText ) ; newText ; List (newText ; existingText )
] ;
result

For that type of thing, I just use List ( $newContent, field ). If there is data, it separates them with a carriage return. If there is not, it strips out extra empty values.

2 Likes

Just so you know where I'm coming from, I quote scripture online, in my writing as wekll as articles most days copying and pasting from biblegateway.com. However, when I copy and paste I get this...


John 14:1-3 King James Version (KJV)

14 Let not your heart be troubled: ye believe in God, believe also in me.

2 In my Father's house are many mansions: if it were not so, I would have told you. I go to prepare a place for you.

3 And if I go and prepare a place for you, I will come again, and receive you unto myself; that where I am, there ye may be also.


When what I want is this...


John 14:1-3
1 - Let not your heart be troubled: ye believe in God, believe also in me.
2 - In my Father's house are many mansions: if it were not so, I would have told you. I go to prepare a place for you.
3 - And if I go and prepare a place for you, I will come again, and receive you unto myself; that where I am, there ye may be also.


I have a crack at it every now and again and have just about sorted it, apart from the issue...
that unless I'm quoting from chapter 1, the site for reasons I do not understand numbers the first verse of the quote as the the chapter number, as seen above, the nearest I've got so far is...


John 14:1-3
14 - Let not your heart be troubled: ye believe in God, believe also in me.
2 - In my Father's house are many mansions: if it were not so, I would have told you. I go to prepare a place for you.
3 - And if I go and prepare a place for you, I will come again, and receive you unto myself; that where I am, there ye may be also.


But as you can see, the first verse is numbered as the chapter [14] rather than 1, yet my little script is still saving me allot of time reformatting every quote I make. The kicker is that if my quote doesn't include the first verse I don't have the numbering issue, but rather get this...


John 14:2-3 King James Version (KJV)

2 In my Father's house are many mansions: if it were not so, I would have told you. I go to prepare a place for you.

3 And if I go and prepare a place for you, I will come again, and receive you unto myself; that where I am, there ye may be also.


Which my script cleans-up to the acceptable.....


John 14:2-3
2 - In my Father's house are many mansions: if it were not so, I would have told you. I go to prepare a place for you.
3 - And if I go and prepare a place for you, I will come again, and receive you unto myself; that where I am, there ye may be also.


Additionally, If I only quote a single verse... I want it to give me this which excludes the inline verse number....


John 14:2
In my Father's house are many mansions: if it were not so, I would have told you. I go to prepare a place for you.


Rather than this which includes it....


John 14:2
2 - In my Father's house are many mansions: if it were not so, I would have told you. I go to prepare a place for you.


I'm not exactly a novice with Filemaker, but acknowledge that my skills are still quite limited, and it is through exercises like this that I learn best, and as mentioned... although my script isn't yet finished it is already saving me allot of time.

Appreciated, Karlos.