Text Parsing Bible Verses

For years I've been copying KJV verses from: https://www.biblegateway.com/
Which when pasted into blogs, articles and debates give me this...


Psalm 22:2-4 King James Version (KJV)

2 O my God, I cry in the day time, but thou hearest not; and in the night season, and am not silent.

3 But thou art holy, O thou that inhabitest the praises of Israel.

4 Our fathers trusted in thee: they trusted, and thou didst deliver them.


When I want this...

Psalm 22:2-4
2 - O my God, I cry in the day time, but thou hearest not; and in the night season, and am not silent.
3 - But thou art holy, O thou that inhabitest the praises of Israel.
4 - Our fathers trusted in thee: they trusted, and thou didst deliver them.

I used Substitute to get rid of "King James Version (KJV)" and change the double ¶¶ to a single ¶, but I'm struggling to add the "dash" between the number and the start of each verse.

I've been experimenting with a loop and various versions of...
LeftWords ( GetValue ( Tx::Text2 ; PatternCount ( Tx::Text2 ; ¶ ) ) ; 1 ) and I'm inching forwards but would appreciate any advice.

I guess I'm classed as an intermediate, though mostly through trial and error... and error! :open_mouth:

The time saved reformatting the text will be hours each month as I am quoting such verses on an almost daily basis and have been for years. Once I have my script I just need to find the quickest way to implement it on my Mac, something I'll consider later.

I purposely didn't include verse 1 above, as it presents a second issue of placing the chapter number in place of the number "1", Why? I don't know, it is simply something the site does and another I'll confront once I have resolved the "Dash" issue....


Psalm 22:1-4 King James Version (KJV)

22 My God, my God, why hast thou forsaken me? why art thou so far from helping me, and from the words of my roaring?

2 O my God, I cry in the day time, but thou hearest not; and in the night season, and am not silent.

3 But thou art holy, O thou that inhabitest the praises of Israel.

4 Our fathers trusted in thee: they trusted, and thou didst deliver them.


3 Likes

Make use of the List and Word functions. Carriage returns and line feeds are list delimiters.

Set $rawData to [the messy text]
set $n to valueCount( $rawData )
set $i to zero
loop
set $i to $i + 1
exit loop if $i > $n
set $lineText to getValue[ $rawData ; $i ]
set $lineNumber to LeftWords( $lineText ; 1 )
... and so on,
1 Like

If the text has the same format from entry to entry, I would first try FMP, but if that's too frustrating, just use a micro-service and the literally hundreds of easy-to-use string formatting methods (aka, functions).

I posted a video here on the forum showing how you can setup a micro-service in about 2 minutes.

HTH

Hi @Karlos welcome to the soup!

Here's a calculation using the While-function introduced with 18, but could also done with a script loop:

Let ( [

_text = 
"Psalm 22:2-4¶
2 O my God, I cry in the day time, but thou hearest not; and in the night season, and am not silent.¶
3 But thou art holy, O thou that inhabitest the praises of Israel.¶
4 Our fathers trusted in thee: they trusted, and thou didst deliver them.¶"

] ;

While ( [ 
_thetext = _text
; _nlines = ValueCount ( _thetext ) 
; _result = ""

] ; _nlines > 0 ; [ 

_line = GetValue ( _thetext ; _nlines )
; _leftword = LeftWords ( _line ; 1 )
; _newline = If ( GetAsText ( Filter ( _leftword ; "0123456789" ) ) = _leftword ; _leftword & " - " & RightWords ( _line ; WordCount ( _line ) - 1 ) ; _line )
; _result = List ( _newline ; _result )
; _nlines = _nlines - 1

] ; _result )

)

best
Otmar

2 Likes

Thanks Otmar.
I've never used 'While' before but will study your reply and see if I can get my head around it! :slight_smile:

Appreciated.

Cheers Malcolm.
I haven't had time to deal with this yet, but will look at your reply soon.

Appreciated.