+1 vote

How can I change any character of a string?

in Engine by (942 points)

1 Answer

+1 vote
Best answer

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:
https://docs.godotengine.org/en/stable/classes/class_string.html

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

by (75 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.