Word Count calculated field?

67 views
Skip to first unread message

Gabriel

unread,
Apr 15, 2025, 11:46:05 AM4/15/25
to mementodatabase
I'm trying to build a simple word count but it's eluding me in Memento (on Android). My approach to get an approximate count would be:
(Original String Length of Text Field) - (String Length of Text Field with Spaces Removed via Replace function)

However, I can't seem to get the Replace function to work at all. 
Like the person here, no matter what I enter I get the error "One string argument and two character arguments are required": https://groups.google.com/g/mementodatabase/c/QCzZVuLxhyA/m/3LTVEP3_BgAJ

Anyone have any thoughts on how to resolve this?

Er Mo

unread,
Apr 15, 2025, 1:15:57 PM4/15/25
to mementodatabase
Hallo
Ich würde den String durchlaufen und ihne in einzelne Einheiten zerlegen . Dann nach Leerzeichen suchen und mitzählen . Für die Wörter müsstes du dann noch 1 hinzufügen . Das könnte man als Schaltflächen Skript ausführen .

Hello
I would loop through the string and break it down into individual units. Then look for spaces and count them. You would then add 1 for the words. This could be executed as a button script.

Ernst

David Gilmore

unread,
Apr 15, 2025, 1:29:28 PM4/15/25
to mementodatabase
It would be helpful if you included your actual script. Javascript syntax can be a little tricky sometimes. To remove blanks:

Unfortunately, the string method "replaceAll" does not exist in Memento Javascript, so you have to run the "replace" method over and over to get all of the blanks removed from your string.

Example:

var buff = "x y z";
var nbuff;
do {
  nbuff = buff.replace(" ", "");
 if (nbuff == buff) break;
  buff = nbuff;
} while (true);
message(buff);

Bill Crews

unread,
Apr 15, 2025, 3:17:13 PM4/15/25
to Gabriel, mementodatabase

--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mementodatabase/294d5435-403f-42cb-b5a2-e1b06b7de776n%40googlegroups.com.

Graham Wood

unread,
Apr 15, 2025, 11:11:29 PM4/15/25
to mementodatabase
this will count words only and not spaces, just put it into a javascript field and change the text field name to your own

var text = entry().field("name");  // edit field name to your own

if (!text || text.trim() === "") {
  null;
} else {
  var words = text.trim().split(/\s+/);
  words.length;
}



Graham Wood

unread,
Apr 15, 2025, 11:26:40 PM4/15/25
to mementodatabase
This script is run from a button field  you can place the results in a text field called Results or whatever you want to name it. 

var text = entry().field("name");

if (!text || text.trim() === "") {
    entry().set("results", null); // Leave results empty if no words
} else {
    var words = text.trim().split(/\s+/);
    entry().set("results", words.length); // Set the word count in the "results" field
}

Reply all
Reply to author
Forward
0 new messages