Encoding combined text fields to Numeric Sequences

  • 0
  • 1
  • Question
  • Updated 1 month ago
  • In Progress
I need all of the smartest QB cats on the block for this one. I have been banging my head against the limits of my Java Script and have come up with nothing that works.

Here is what I need to accomplish:

I need to take 3 text fields ([text1]&t[text2]&[text3]) and turn them into a string of numbers based on their alpha make up. Example: [a cat]&[the dog]&[a rat] = 10312222850417118122 (space can be 0)

Does anyone have a working formula for this?
Photo of QuickBase Girl

QuickBase Girl

  • 358 Points 250 badge 2x thumb
  • Out of options

Posted 1 month ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 28,304 Points 20k badge 2x thumb
There are several problems with your proposed encoding:

(1) what happens to upper case letters or characters outside the range a-z?

(2) your encoding "10312222850417118122" for "a catthe doga rat" is wrong as "t" is the 20'th letter of the alphabet not the 22'nd. There are more errors later in the string.

(3) if you intend to decode your string at some point it isn't clear how say the sub-string "22" would be decoded as it could be "bb" or "v".

In any event this fragment of code patches some of these issues and deals with issue (3) by inserting a space delimiter between the encodings for individual characters:
var string = "a catthe doga rat".toLowerCase();
string =  string.replace(/./g, function(c) {
  var charCode = c.charCodeAt(0);
  if (charCode == 32) {
    return 0 + " ";
  } else {
    return c.charCodeAt(0) - 96 + " ";
  }
});
console.log(string);
//output:
//1 0 3 1 20 20 8 5 0 4 15 7 1 0 18 1 20
(Edited)
Photo of QuickBase Girl

QuickBase Girl

  • 358 Points 250 badge 2x thumb
The set given was an example. 22 was a miscount on my tired and worn out part. I will not be decoding it. It is for the numerical need only. 
Photo of QuickBase Girl

QuickBase Girl

  • 358 Points 250 badge 2x thumb
Looking more to this: ([ToText] is already all lowercase, no space, concatenated text string from 3 different fields)

var text String = [ToText];

I need it to be numbers with no spaces between (so we can nix the +" "'s)

For some reason, it keeps throwing errors.  not liking any of the .'s
(Edited)
Photo of QuickBase Girl

QuickBase Girl

  • 358 Points 250 badge 2x thumb
These are examples of the Text strings I am working with:

accountsreceivablespecialistoperationsfrontlineservdel
corporateservicesanalystoperationsprofessional
m2mxcoordinatoroperationsadministrative
Photo of QuickBase Girl

QuickBase Girl

  • 358 Points 250 badge 2x thumb
Any links to any help articles or formulas would also be helpful. I have found lots of articles on different solutions, and none seem to work. :(
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 28,134 Points 20k badge 2x thumb
This can't be done with a conventional formula. You have to use JavaScript. However, there are minor details to resolve as to what that JavaScript should be because it isn't clear what the script should do in all cases. Your third example introduces the possibility that numbers may be included in the source string in which case there will be a "-" character in the output string:
var string = "m2mxcoordinatoroperationsadministrative".toLowerCase();
string =  string.replace(/./g, function(c) {
  var charCode = c.charCodeAt(0);
  if (charCode == 32) {
    return 0;
  } else {
    return c.charCodeAt(0) - 96;
  }
});
//"13-46132431515184914120151815165181209151419141391491920181209225"
This script removes the spaces between characters (although they are very useful during debugging). You still have to accommodate all possible character values that could possibly be inputs with additional logic. 

Once you get the script working from the console you can implement it with (1) the IOL technique or (2) the OEH (On Error HTML) technique using the OEH Machine which automatically creates the formula (ie no code page):

(Edited)