[SOLVED] Put something inside string

Is there a way to shove in something in the middle of string?

Like i have string “Cool”
And i wanna shove in there
But i want to put “OO” between “oo” so we get “CoOOoL”

Is it possible to do it without breaking string into pieces with variables
And just with some expression?

I was trying StrAt but i think i do not understand well how it works
I was only able to put something at beginning of string like left side 1st character

You can use this expression:
SubStr(textobject.Text::Value(), 0, 2) + “OO” + SubStr(textobject.Text::Value(), 2, StrLength(textobject.Text::Value()))

Breaking it down:

  • get part of the string starting from letter index 0 with length of 2 letters (letter index 0-1)
  • add “OO”
  • add part of the string starting from letter index 2 (which is the 3rd letter) to the end of the string.

I used this to change the text in a textobject “textobject.Text::Value()”. If you want to change a string in a variable, then replace it with “VariableString(stringvar)”.

There’s an extension called regular expression (RegEx) the documentation seems to be lacking but it uses the RegEx in JavaScript. So, you can search for how to use the replace method. It might be overkill. It’s like find and replace on steroids.

JavaScript has more ways than GD for text manipulation. It takes more lines to get the value and return it than to actually do the replacing.

Actually i was going to find a way to shove in separators for numbers
To put in 1000 and spit out 1,000
Not breaking string in separate variables and using on expressions inside singe text object
And i found other way to do it

And seems it work pretty well
But i gonna save your method since it seems useful
THX

ToString(Variable(Score))+"
"+StrAt(",",(StrLength(StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-19)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-20)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-21)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-22)))-4)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-21)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-20)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-19)+StrAt(",",(StrLength(StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-16)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-17)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-18)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-19)))-4)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-18)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-17)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-16)+StrAt(",",(StrLength(StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-13)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-14)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-15)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-16)))-4)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-15)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-14)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-13)+StrAt(",",(StrLength(StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-10)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-11)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-12)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-13)))-4)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-12)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-11)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-10)+StrAt(",",(StrLength(StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-7)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-8)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-9)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-10)))-4)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-9)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-8)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-7)+StrAt(",",(StrLength(StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-4)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-5)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-6)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-7)))-4)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-6)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-5)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-4)+StrAt(",",(StrLength(StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-1)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-2)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-3)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-4)))-4)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-3)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-2)+StrAt(ToString(Variable(Score)),(StrLength(ToString(Variable(Score))))-1)

It automatically adds comma IF string length is above increment of 3
So if string is 4 digits long or 7 or 10 and so go on
It automatically adds it and removes if it is less

2024-03-08_23_53_7l03wBnOmp_GDevelop

And now we can go negative
2024-03-09_00_12_iOYmkXdlwy_GDevelop

Just by checking if var is under or equal/above 0
And storing original variable to text object then multiplying it by -1 which returns positive number
And so just adding in text - at the beginning

1 Like

Actually i am familiar with RegEx
But anyway like my above post states i found my way around it
THX

1 Like