To shorten a character variable

Good afternoon everybody!

I’m pretty sure it must be obvious but I can’t find how to drop letters from a variable.
Here what I want to do:
Readers can choose their ship’s name. Let’s say I use a variable I name $Vaisseau_nom. At some point I will want to use the ship’s name in the text. Pretty straightforward, I write my text and at some point I use $Vaisseau_nom.

Les moteurs de $Vaisseau_Nom produisent un bruit assourdissant. Let’s say the ship is named La Cigale:
Les moteurs de La Cigale produisent un bruit assourdissant.
(La Cigale’s engines produce a deafening noise in English).

Easy? Sure. But French is quite irritating at this point. Every name in French is either masculine or feminine. So if my ship has a feminine name, the above sentence works perfectly. However if the name is masculine this doesn’t work, the words de le have to become du. Example, with the name Le Dauphin:
Les moteurs du Dauphin produisent un bruit assourdissant.
At this point, I need to drop 'Le ’ from my variable $Vaisseau_nom. There’s plenty of manipulations of numeric variables, but I feel, and I may be very wrong on this, that manipulations of character variables are less documented.

What I need is something quite simple, a function, a feature, anything allowing me to write only the characters from the ‘D’, that’s akin as (R language):
oldstring ← “Le Dauphin”
newstring ← substr(oldstring,4,nchar(oldstring))
newstring is “Dauphin”

I thank you for reading so far!

Twine Version: 2.3.13
Story Format: 2.34.1

I think you could use the <<print >> macro and call one of JavaScript’s string manipulation functions on the variable. (Links: SugarCube v2 Documentation, String.prototype.substring() - JavaScript | MDN)

Something like this should work:
<<print $Vaisseau_nom.substring(3)>>

If you need something more flexible/general, you could wrap it in a JavaScript function which you add to the “Story JavaScript” or to a template.

1 Like

Many thanks!