Hi All,
How would I go about selecting the last 15 characters in a predetermined string - for example, an address search API query returns the following
Number,Street Name,City,County,Postcode,A00008208248,ST
In this instance, all I require for the next API search is "A00008208248,ST" - How do I go about taking just this part of the string?
Jamie
1 Like
Welcome @ModutelUK ,
FYI, this is the perfect type of question for ChatGPT and its kind:
Prompt:
"In JS how to select just the last 15 characters of a string?"
Response:
In JavaScript, you can select the last 15 characters of a string by using the slice()
method. Here's how you can do it:
let str = "This is a sample string and we want the last 15 characters.";
let last15 = str.slice(-15);
console.log(last15); // Outputs: "15 characters."
If the string contains fewer than 15 characters, this approach will return the entire string. If you want exactly 15 characters and no less, you'll need to add a conditional check.
I didn't even think of ChatGPT.
Thank you Bradly.
I am using ChatGPT more and more for coding questions like this - JS and SQL mostly. I even use it to debug code - I'll give it the code, tell it the error and it will usually find a fix - sometime completely refactors my code/SQL to improve it. It is saves me time and teaches me new things.
Even if I know how to do something, giving ChatGPT a prompt and having it build the code for me can be faster than me typing it, and it won't have all the bad typist typos which I am (in)famous for.
Retool's built in ChatGPT support for their code windows is coming along as well.
2 Likes