# Help with variables in Strings

**URL:** <https://forum.godotengine.org/t/help-with-variables-in-strings/148143>\
**Category:** Help\
**Tags:** godot-4\
**Created:** [December 5, 2026, 10:09pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143 "2026-12-05T22:09:50Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![TQS\_suki](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/t/e495f1/32.png) [@TQS\_suki](https://forum.godotengine.org/u/TQS_suki)\
**Post date:** [December 5, 2026, 10:09pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/1 "2026-12-05T22:09:50Z")

</div>

### Godot Version

Godot 4.1.1

### Question

The plan is for the player to put a name in a variable stored in a global script. The way the player inserts the name is not done but I don’t think it’s important for this. The variable is “your\_name”

 ![variable](https://forum.godotengine.org/uploads/default/original/3X/f/7/f7f5ee3e8a5c1e99a74d84e219b5b6105b62ecf1.png)

And what I was thinking was to put that variable on a string in the editor

 ![texto](https://forum.godotengine.org/uploads/default/original/3X/f/f/ff0b7b55042bf276ce030c97a47b8f4c239d3189.png)

Something like this. Not in the code, I know that is posible.

Is this even posible? If it is, how would you implement it?

Thank you.

---

<div class="post-metadata">

**Author:** ![normalized](https://forum.godotengine.org/user_avatar/forum.godotengine.org/normalized/32/58558_2.png) [@normalized](https://forum.godotengine.org/u/normalized)\
**Post date:** [December 5, 2026, 10:20pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/2 "2026-12-05T22:20:39Z")

</div>

Decide on some prefix or delimiters that signifies a “variable” in your texts. It can be `$your_name` or `[your_name]`, then use regular expressions to replace that with the actual name in the string.

---

<div class="post-metadata">

**Author:** ![TQS\_suki](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/t/e495f1/32.png) [@TQS\_suki](https://forum.godotengine.org/u/TQS_suki)\
**Post date:** [December 5, 2026, 10:26pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/3 "2026-12-05T22:26:21Z")

</div>

Where would I put the prefix/delimiter? On the code?

---

<div class="post-metadata">

**Author:** ![normalized](https://forum.godotengine.org/user_avatar/forum.godotengine.org/normalized/32/58558_2.png) [@normalized](https://forum.godotengine.org/u/normalized)\
**Post date:** [December 5, 2026, 10:29pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/4 "2026-12-05T22:29:16Z")

</div>

On the words in your text that you want to represent variables. So similarly to what you actually already have: `Hello, my name is $your_name`

`$your_name` now represents a “variable” that needs to be replaced with the actual name. Since there is a specific prefix, it’s easy to do search/replace operation using regex.

---

<div class="post-metadata">

**Author:** ![TQS\_suki](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/t/e495f1/32.png) [@TQS\_suki](https://forum.godotengine.org/u/TQS_suki)\
**Post date:** [December 5, 2026, 10:36pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/5 "2026-12-05T22:36:15Z")

</div>

I do have it.

 ![seaside.tscn - Klamato - Godot Engine 05_12_2026 23_30_01](https://forum.godotengine.org/uploads/default/original/3X/3/c/3c97c48c0a02e07ddb5857d92162b9cd2f457a77.png)

And also I have the global variable reference in the actual code of the text.

 ![text2](https://forum.godotengine.org/uploads/default/original/3X/9/0/9098cf5b20b3a4286db1e350bc554b7b40c9989d.png)

But when I run the game, it says $your\_name instead of what the variable is.

 ![Screenshot 05_12_2026 23_30_11](https://forum.godotengine.org/uploads/default/original/3X/2/1/212bd8efa83a55d7a9acba8edb349c0318fab74f.png)

Do I need to do something more? I’m sorry if it is to many questions

---

<div class="post-metadata">

**Author:** ![tibaverus](https://forum.godotengine.org/user_avatar/forum.godotengine.org/tibaverus/32/43649_2.png) [@tibaverus](https://forum.godotengine.org/u/tibaverus)\
**Post date:** [December 5, 2026, 10:40pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/6 "2026-12-05T22:40:11Z")

</div>

As mentioned in the original reply, you need to use regex to replace your variables in text.

> **[RegEx](https://docs.godotengine.org/en/stable/classes/class_regex.html)**
>
> Inherits: RefCounted\< Object Class for searching text for patterns using regular expressions. Description: A regular expression (or regex) is a compact language that can be used to recognize str...

---

<div class="post-metadata">

**Author:** ![VoidEssy](https://forum.godotengine.org/user_avatar/forum.godotengine.org/voidessy/32/87045_2.png) [@VoidEssy](https://forum.godotengine.org/u/VoidEssy)\
**Post date:** [December 5, 2026, 10:43pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/7 "2026-12-05T22:43:16Z")

</div>

I think parametrised string would work in your case perfectly.

Ref:

> **[String](https://docs.godotengine.org/en/stable/classes/class_string.html#class-string-method-format)**
>
> bool begins\_with(text: String) const 🔗 | A built-in type for strings. Description: This is the built-in string Variant type (and the one used by GDScript). Strings may contain any number of Unicode characters, and expose methods useful fo...

> **[GDScript format strings](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_format_string.html)**
>
> Godot offers multiple ways to dynamically change the contents of strings: Format strings: var string = "I have %s cats." % "3", The String.format() method: var string = "I ...

---

<div class="post-metadata">

**Author:** ![normalized](https://forum.godotengine.org/user_avatar/forum.godotengine.org/normalized/32/58558_2.png) [@normalized](https://forum.godotengine.org/u/normalized)\
**Post date:** [December 5, 2026, 10:55pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/8 "2026-12-05T22:55:01Z")

</div>

Yeah `String.format()` is simpler than regex but sufficient for what you’re trying to do.

---

<div class="post-metadata">

**Author:** ![TQS\_suki](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/t/e495f1/32.png) [@TQS\_suki](https://forum.godotengine.org/u/TQS_suki)\
**Post date:** [December 5, 2026, 11:14pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/9 "2026-12-05T23:14:31Z")

</div>

I’m not really understanding any of both methods. I mean I do kinda understand the second one with format strings, but I’m not able to implement it in my case.

---

<div class="post-metadata">

**Author:** ![VoidEssy](https://forum.godotengine.org/user_avatar/forum.godotengine.org/voidessy/32/87045_2.png) [@VoidEssy](https://forum.godotengine.org/u/VoidEssy)\
**Post date:** [December 5, 2026, 11:24pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/10 "2026-12-05T23:24:46Z")

</div>

Do you assign the formatted string after it gets formatted?

I’ve quick clobbered it together so do verify but this should basically work

```auto
extends Label

var your_name: String = "MySuperCoolName" #In YourCase Global.your_name

func _ready() -> void:
	text = "Your name %s" % your_name # Technically could go instead of your_name just Global.your_name if you don't need the local variable.
	self.text = "Your name %s" % your_name # Same as above but more explicit that it's a 'self-assigned' in case of the Label example.

```

I’ve not tested it (too much over-head to setup and 100% validate) but hopefully gives you rough idea.

---

<div class="post-metadata">

**Author:** ![TQS\_suki](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/t/e495f1/32.png) [@TQS\_suki](https://forum.godotengine.org/u/TQS_suki)\
**Post date:** [December 5, 2026, 11:30pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/11 "2026-12-05T23:30:30Z")

</div>

It does work!!!

Thank you very much

---

<div class="post-metadata">

**Author:** ![TQS\_suki](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/t/e495f1/32.png) [@TQS\_suki](https://forum.godotengine.org/u/TQS_suki)\
**Post date:** [December 5, 2026, 11:30pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/12 "2026-12-05T23:30:52Z")

</div>

And thank you too for your help.

---

<div class="post-metadata">

**Author:** ![VoidEssy](https://forum.godotengine.org/user_avatar/forum.godotengine.org/voidessy/32/87045_2.png) [@VoidEssy](https://forum.godotengine.org/u/VoidEssy)\
**Post date:** [December 5, 2026, 11:31pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/13 "2026-12-05T23:31:38Z")

</div>

Tinker around with it to get the feel for it.

![hanamaru-kindergarten-anime](https://forum.godotengine.org/uploads/default/original/3X/c/7/c7d1e4b034263a3db2a4c088671254eb0fb21a88.webp)

---

<div class="post-metadata">

**Author:** ![TQS\_suki](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/t/e495f1/32.png) [@TQS\_suki](https://forum.godotengine.org/u/TQS_suki)\
**Post date:** [December 5, 2026, 11:32pm UTC](https://forum.godotengine.org/t/help-with-variables-in-strings/148143/14 "2026-12-05T23:32:45Z")

</div>

yeah, it works exacly as I espected
