Change characters of a string

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Help me please

How can I change any character of a string?

:bust_in_silhouette: Reply From: clownshoe

say you have a string like this:
var s=“our string”

and you want to capitalise the s in string.

you can change with this:
s[4] = “S”

you can treat a string like an array, and alter it’s values by the index of the characters.
so with “our string”
o == index 0
u == index 1
r == index 2
== index 3
s == index 4

there are also a bunch of helper functions in the String class:

so the find the first instance of “s” within the string you could call:
var s_index = find (“s”, from=0)

so you could also call
s = s.replace(“s”, “S”)

which would replace all instances of s with S