[ stupid mod question ] is there a string search functionality available ?

The place to discuss scripting and game modifications for X Rebirth.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

[ stupid mod question ] is there a string search functionality available ?

Post by Jey123456 »

i'm looking for something in the like of strpos in most languages (strstr in C).

Basicly, i want to check if a string contain a substring. I could not find any character by character access either. I had a look through the xsd, but had no luck finding anything that may help me (altho i missed some other things in the past)
User avatar
ybeline
Posts: 83
Joined: Sun, 22. Aug 10, 13:55
x4

Post by ybeline »

Hello Jey123456,



This might help you:

list / indexof.{$value} / integer / "Index of first occurrence of $value in the list (1-based), or 0 if not found"

Example:

Code: Select all

$test_list=[5,2,7,4]
$test_list.indexof.{7}='3'

Is it what you're looking for?

Regards,

ybeline
Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

Post by Jey123456 »

if it works on strings, yes.

for instance, if i have a string
$varstring='imacoolstring'
$varstring='imacoolerstring'
$varstring='imanotherstring'


i want a way to way to check if it contain the string 'cool'
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

<substitute_text source="$string1" text="$string2"><replace string="'cool'" with="''"/></substitute_text>

and compare $string1 with $string2 - if they are the same it is not in ther, if they differ it is in there.
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)
User avatar
Fumblesneeze
Posts: 75
Joined: Tue, 26. Nov 13, 10:07
x3tc

Post by Fumblesneeze »

UniTrader wrote:<substitute_text source="$string1" text="$string2"><replace string="'cool'" with="''"/></substitute_text>

and compare $string1 with $string2 - if they are the same it is not in ther, if they differ it is in there.
..wow

I must say this xml scripting is genius from a modding perspective but it sure doesnt make mundane tasks easier xD
Streaming while writing mods: twitch.tv/fumblesneeze
Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

Post by Jey123456 »

ah, yea, that will work fine =D. Not exactly optimal, but no matter, its clean enough to achieve the goal.

Thank you
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

i know its more a workaround and i would almost bet there is a cleaner way, but this one is the only one i know atm (i think there is an operator for expressions which achives the same or better(string position), but without doc its impossible to find it)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

Return to “X Rebirth - Scripts and Modding”