Sort text excluding articles

Viewing 2 reply threads
  • Author
    Posts
  • March 24, 2023 at 10:53 AM #49202

    Susan Chute
    Participant

    Hello there,
    I just want to say I am enjoying this database, which has solved many problems I previously had with LibreBase. I posted a good review in the Apple Store. It seems very robust. I’m not up to scripting in JavaScript yet (after all, I just finished learning SQL in the W3school for LibreBase). So my question is, I have a big database of poems. I want to sort it by title, but for the sort to ignore A, An and The. I know that you could probably write a script, but as of yet I don’t know how (start after 1st 2, 3, or 4 characters, maybe, is part of it?). Can you explain? or is there an easier way?
    Thanks for TapForms! Yay!

    March 24, 2023 at 5:56 PM #49203

    Daniel Leu
    Participant

    Yeah, you could write a script or use the calculation field to strip “A “, “An “, or “The ” from the title string. The script or calculation would then return the shortened title on which you could perform your search.

    Using calculation seems to be a bit more complicated than using a script:

    function Stripped_Title() {
    	// Define Id of title field
    	const title_id = 'fld-dec6b20e27d343e181e37a813624b467';
    	let title = record.getFieldValue(title_id);
    
    	// Check for "A "
    	if (title.toLowerCase().substr(0,2) == "a "){
    		return title.substr(2)
    	}	
    
    	// Check for "An "
    	if (title.toLowerCase().substr(0,3) == "an "){
    		return title.substr(3)
    	}	
    	
    	// Check for "The "
    	if (title.toLowerCase().substr(0,4) == "the "){
    		return title.substr(4)
    	}
    }
    
    Stripped_Title();
    

    I don’t know if all your titles start with an uppercase character. So I translate them to lowercase to catch “a”, “an” and “the” as well. Good luck!

    • This reply was modified 1 year, 9 months ago by Daniel Leu.
    March 24, 2023 at 6:04 PM #49205

    Susan Chute
    Participant

    Thank you, Daniel. I’ll go about trying this.

Viewing 2 reply threads

You must be logged in to reply to this topic.