JS deletes the implementation code of the last character of the string

  • 2020-03-30 01:46:15
  • OfStack

String s = "1,2,3,4,5,"

Target: delete the last ","

Methods:
The one that I use the most is substring, and this is the one that I use all the time

S = s.s ubstring (0, s.l ength - 1)

I've been seeing this a lot lately, like there's a string "[lightinthebox]," but I just need the lightinthebox, not the []. How to get rid of it in a quick and effective way.
StringObject. Substring (start,stop) // intercepts the start and end strings.
StringObject. Substr (start,length) // intercepts the start and string length.
So let's think about all of these, the linkage of the sum method.
StringObject. Substr (1). Substring (-1,0) // will work
I'm just going to say a intercept here, by the way, and now there's always the temptation to change the ones place to two places. For example, 9 is displayed as 09 for formatting alignment.
A lot of things are done to see if this number is less than 10, to see if we can add a 0
If we use a string, we don't have to judge anything, we just add one bit, we just cut out the last two bits, and then 01,010,011 becomes 01, 10, 011
I did not say the specific, lest anyone laugh at me

It's been tested.


Related articles: