Skip to main content
Level 3
Sep 25, 2022 3:39 AM UTC
Solved

how to get last two characters from string


In dialog of the componenet im going to author field it is like tag field

json data look as below 

"Icon" : "india:delhi/NR" ,

in htl when i try print  
icon: ${properties.icon}   // its coming full tag like    india:delhi/NR

But i want to print NR only

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Akanksha_Singh
Akanksha_SinghAccepted solution
Level 2
Sep 28, 2022 11:33 AM UTC

Hi @user96222 

You can use custom scripting:

var string = "StringABC";
var last2Char = string.slice(-2);

console.log(last2Char);

3 replies

Perrin_Ennen
Community Advisor
Community Advisor
Sep 26, 2022 7:41 AM UTC

Maybe something like this - before you write it as JSON set the variable first.

 

const str = '${properties.icon}';

const last2 = str.slice(-2);

Translate
Sep 27, 2022 5:53 AM UTC

i think it wont work in htl file right.

I want in htl file

Translate
Akanksha_Singh
Akanksha_SinghAccepted solution
Level 2
Sep 28, 2022 11:33 AM UTC

Hi @user96222 

You can use custom scripting:

var string = "StringABC";
var last2Char = string.slice(-2);

console.log(last2Char);

Translate