Josem
December 22, 2024, 8:52pm
1
I'm thinking of using TB to create a transcoding tool to generate URIs, defining the equivalence of the characters:
'ó' -> 'o'
'(' -> ''
')' -> ''
'ñ' -> 'n'
' ' -> '-'
It would be from the string stored in the clipboard and the first thing would be to convert it to lowercase...
Can you help me with the rest?
Examples:
Pantalón caballero (Talla XL) -> pantalon-caballero-talla-xl
Puños de camisa blanca -> punos-de-camisa-blanca
Thanks in advance for this awesome tool!
Hey @Josem ,
I used a Keyed list to define the list of characters and the mapping.
I took string and split it with a list of characters using split()
Now used map() to iterate through each character and map it to the relevant characters. I also used catch() , if the character is not present in the list, switch to the source character.
Then used join() to join the characters back to single sentence and lower() it for lower case string.
You can use the {clipboard} in place of the string as per your needs.
In the snippet below, I used {note} just for removing new lines. This might not be required in the real snippet.
{converted_chars=[
"ó": "o",
"(": "",
")": "",
"ñ": "n",
" ": "-"
]}
Pantalón caballero (Talla XL) = {note: preview=no}
{letters1=split("Pantalón caballero (Talla XL)", "")}
{converted1=map(letters1, letter -> catch(converted_chars[letter], letter))}
{endnote}{=lower(join(converted1, ""))}
==== ==== ==== ==== ====
Puños de camisa blanca = {note: preview=no}
{letters2=split("Puños de camisa blanca", "")}
{converted2=map(letters2, letter -> catch(converted_chars[letter], letter))}
{endnote}{=lower(join(converted2, ""))}
Please let me know if this helps,
1 Like
Josem
December 23, 2024, 9:20am
3
Amazing!
Thank you so much, does exactly what I need
Thank you so much!
1 Like
Josem
January 7, 2025, 3:09pm
4
I'm seeing that 3 carriage returns are added at the beginning
Maybe it's an implementation error on my part...
CODE:
{converted_chars=[
"á": "a",
"é": "e",
"í": "i",
"ó": "o",
"ú": "u",
"(": "",
")": "",
"ñ": "n",
" ": "-",
" ": "-"
]}
{letters1=split(lower({clipboard}), "")}
{converted1=map(letters1, letter -> catch(converted_chars[letter], letter))}
{=join(converted1, "")}
STRING ON CLIPBOARD:
Uniforme (niño) camisa azul y pantalón gris
RESULT:
(carriage return )
(carriage return )
(carriage return )
uniforme-nino-camisa-azul-y-pantalon-gris
Any suggestion @VinodGubbala ?
TIA
Josem
January 9, 2025, 11:00pm
5
The problem was that those carriage returns were in the editor, after each sentence.
I put everything in one line and it was solved.