Skip to content

Tag: string

Replace every nth character from a string

I have this JavaScript: I aim to replace every fourth letter in the string abcdefoihewfojias with |, so it becomes abc|efo|….etc,but I do not have a clue how to do this. Answer To support re-usability and the option to wrap this in an object/function let’s parameterise it:

Trim specific character from a string

What’s the JavaScript equivalent to this C# Method: C# trims the selected character only at the beginning and end of the string! Answer One line is enough: A general solution: Parameter c is expected to be a character (a string of length 1). As mentionned in the comments, it might be useful to support m…

Isolate part of a string from index to next whitespace?

What’s the best way to do this solve for this next whitespace? result: things Answer You could do the whole thing with a regular expression: What that does is match an exclamation point, followed by some amount of non-whitespace (that’s what S means — s with a lower-case “s” matches wh…