Zum Inhalt

string_util

Quelle: base/tealdef/scripts/string_util.d.tl

Hinweise

Typen von /scripts/string_util.tl (StringUtil): Platzhalter der Form {placeholder} in Strings füllen und Anfang oder Ende eines Strings prüfen. Die Funktionen stammen aus dem alten /scripts/stringutil.lua.

StringUtil

record global base/tealdef/scripts/string_util.d.tl:3

global record StringUtil

Laden: local string_util = ug_require "::/scripts/string_util.tl" as StringUtil

Hinweise

String-Helfer, die ug_require "/scripts/string_util.tl" zurückgibt.

Funktionen

format(string) : string base/tealdef/scripts/string_util.d.tl:4

Aufruf: string_util.format(…)

Hinweise

Ersetzt Platzhalter {name} in einem String durch Werte aus einer Tabelle (das alte string.interp).

Rückgabe string

Details

  • Mit einer Tabelle wird {name} durch tab.name ersetzt (oder durch tab[number] bei {1}, {2}, ...). Unbekannte Platzhalter bleiben stehen.
  • Ein leeres {} wird automatisch nummeriert: Das erste {} wird zu {1}, das nächste zu {2} und so weiter.
  • Mit String-Argumenten statt einer Tabelle (format(s, a, b, ...)) werden die {}-Platzhalter der Reihe nach mit a, b, ... gefüllt.

Beispiel

-- from base/content/scripts/scripts/table_util.tl
log.error(string_util.format("No comparison of functions (key = {}), need '{}' sibling attribute on both tables to compare instead", toString(key), compareProxyKey))
Im Basisspiel verwendet: 26-mal in 9 Dateien

base/content/game_mechanics/game_mechanics/company/company_util.tl:128

local str = string_util.format("Deprecated use of company metadata rankAndPermits together with permitKey ({permitKey} is already used for {otherUse})", {permit
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:247
tooltip = app_util.isGamepadInputMode() and string_util.format(_("Supplied: {count}"), { count = text }) or nil,
base/content/gui/gui/entity_window/town/town.tl:246
tooltip = app_util.isGamepadInputMode() and string_util.format(_("Received: {count}"), { count = text }) or nil,
base/content/gui/gui/main/react.lua:70
log.warning(string_util.format("RegisterExtensionPoint failed because the name is already used: {name}", {name = fullyQualifiedName}))
base/content/gui/gui/menu/new_game_react_util.tl:39
local txt = string_util.format("Climate not found: {climate}", {climate = climate})
base/content/gui/gui/node_editor/layer_nodes.script.tl:292
local txt = string_util.format("Attempting to spawn {numRivers} rivers with {numAttempts} sample locations, spawned {numActual} rivers (of which {numInnerRivers
… und 3 weitere Dateien.

format(string, {string : string}) : string base/tealdef/scripts/string_util.d.tl:5

Aufruf: string_util.format(…)

Hinweise

Ersetzt Platzhalter {name} in einem String durch Werte aus einer Tabelle (das alte string.interp).

Rückgabe string

Details

  • Mit einer Tabelle wird {name} durch tab.name ersetzt (oder durch tab[number] bei {1}, {2}, ...). Unbekannte Platzhalter bleiben stehen.
  • Ein leeres {} wird automatisch nummeriert: Das erste {} wird zu {1}, das nächste zu {2} und so weiter.
  • Mit String-Argumenten statt einer Tabelle (format(s, a, b, ...)) werden die {}-Platzhalter der Reihe nach mit a, b, ... gefüllt.

Beispiel

-- from base/content/scripts/scripts/table_util.tl
log.error(string_util.format("No comparison of functions (key = {}), need '{}' sibling attribute on both tables to compare instead", toString(key), compareProxyKey))
Im Basisspiel verwendet: 26-mal in 9 Dateien

base/content/game_mechanics/game_mechanics/company/company_util.tl:128

local str = string_util.format("Deprecated use of company metadata rankAndPermits together with permitKey ({permitKey} is already used for {otherUse})", {permit
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:247
tooltip = app_util.isGamepadInputMode() and string_util.format(_("Supplied: {count}"), { count = text }) or nil,
base/content/gui/gui/entity_window/town/town.tl:246
tooltip = app_util.isGamepadInputMode() and string_util.format(_("Received: {count}"), { count = text }) or nil,
base/content/gui/gui/main/react.lua:70
log.warning(string_util.format("RegisterExtensionPoint failed because the name is already used: {name}", {name = fullyQualifiedName}))
base/content/gui/gui/menu/new_game_react_util.tl:39
local txt = string_util.format("Climate not found: {climate}", {climate = climate})
base/content/gui/gui/node_editor/layer_nodes.script.tl:292
local txt = string_util.format("Attempting to spawn {numRivers} rivers with {numAttempts} sample locations, spawned {numActual} rivers (of which {numInnerRivers
… und 3 weitere Dateien.

format(string, {string : string}) : string base/tealdef/scripts/string_util.d.tl:6

Aufruf: string_util.format(…)

Hinweise

Ersetzt Platzhalter {name} in einem String durch Werte aus einer Tabelle (das alte string.interp).

Rückgabe string

Details

  • Mit einer Tabelle wird {name} durch tab.name ersetzt (oder durch tab[number] bei {1}, {2}, ...). Unbekannte Platzhalter bleiben stehen.
  • Ein leeres {} wird automatisch nummeriert: Das erste {} wird zu {1}, das nächste zu {2} und so weiter.
  • Mit String-Argumenten statt einer Tabelle (format(s, a, b, ...)) werden die {}-Platzhalter der Reihe nach mit a, b, ... gefüllt.

Beispiel

-- from base/content/scripts/scripts/table_util.tl
log.error(string_util.format("No comparison of functions (key = {}), need '{}' sibling attribute on both tables to compare instead", toString(key), compareProxyKey))
Im Basisspiel verwendet: 26-mal in 9 Dateien

base/content/game_mechanics/game_mechanics/company/company_util.tl:128

local str = string_util.format("Deprecated use of company metadata rankAndPermits together with permitKey ({permitKey} is already used for {otherUse})", {permit
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:247
tooltip = app_util.isGamepadInputMode() and string_util.format(_("Supplied: {count}"), { count = text }) or nil,
base/content/gui/gui/entity_window/town/town.tl:246
tooltip = app_util.isGamepadInputMode() and string_util.format(_("Received: {count}"), { count = text }) or nil,
base/content/gui/gui/main/react.lua:70
log.warning(string_util.format("RegisterExtensionPoint failed because the name is already used: {name}", {name = fullyQualifiedName}))
base/content/gui/gui/menu/new_game_react_util.tl:39
local txt = string_util.format("Climate not found: {climate}", {climate = climate})
base/content/gui/gui/node_editor/layer_nodes.script.tl:292
local txt = string_util.format("Attempting to spawn {numRivers} rivers with {numAttempts} sample locations, spawned {numActual} rivers (of which {numInnerRivers
… und 3 weitere Dateien.

format(string, string, ...: any) : string base/tealdef/scripts/string_util.d.tl:7

Aufruf: string_util.format(…)

Hinweise

Ersetzt Platzhalter {name} in einem String durch Werte aus einer Tabelle (das alte string.interp).

Rückgabe string

Details

  • Mit einer Tabelle wird {name} durch tab.name ersetzt (oder durch tab[number] bei {1}, {2}, ...). Unbekannte Platzhalter bleiben stehen.
  • Ein leeres {} wird automatisch nummeriert: Das erste {} wird zu {1}, das nächste zu {2} und so weiter.
  • Mit String-Argumenten statt einer Tabelle (format(s, a, b, ...)) werden die {}-Platzhalter der Reihe nach mit a, b, ... gefüllt.

Beispiel

-- from base/content/scripts/scripts/table_util.tl
log.error(string_util.format("No comparison of functions (key = {}), need '{}' sibling attribute on both tables to compare instead", toString(key), compareProxyKey))
Im Basisspiel verwendet: 26-mal in 9 Dateien

base/content/game_mechanics/game_mechanics/company/company_util.tl:128

local str = string_util.format("Deprecated use of company metadata rankAndPermits together with permitKey ({permitKey} is already used for {otherUse})", {permit
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:247
tooltip = app_util.isGamepadInputMode() and string_util.format(_("Supplied: {count}"), { count = text }) or nil,
base/content/gui/gui/entity_window/town/town.tl:246
tooltip = app_util.isGamepadInputMode() and string_util.format(_("Received: {count}"), { count = text }) or nil,
base/content/gui/gui/main/react.lua:70
log.warning(string_util.format("RegisterExtensionPoint failed because the name is already used: {name}", {name = fullyQualifiedName}))
base/content/gui/gui/menu/new_game_react_util.tl:39
local txt = string_util.format("Climate not found: {climate}", {climate = climate})
base/content/gui/gui/node_editor/layer_nodes.script.tl:292
local txt = string_util.format("Attempting to spawn {numRivers} rivers with {numAttempts} sample locations, spawned {numActual} rivers (of which {numInnerRivers
… und 3 weitere Dateien.

starts(string, string) : boolean base/tealdef/scripts/string_util.d.tl:9

Aufruf: string_util.starts(…)

Hinweise

True, wenn der erste String mit dem zweiten beginnt.

Rückgabe boolean

Im Basisspiel verwendet: 21-mal in 9 Dateien

base/content/game_mechanics/game_mechanics/achievements/achievements.script.tl:17

return string_util.starts(res, "::/vehicle")
base/content/game_mechanics/game_mechanics/company/company_static_util.tl:49
if string_util.starts(permitKey, "::") then
base/content/gui/gui/entity_window/make_non_entity_window.tl:20
elseif string_util.starts(nonEntity, "subsidy_") then
base/content/gui/gui/main/content_card.tl:73
if string_util.starts(calloutTextHACK, "CALLOUT_") then
base/content/mission/mission/mission_sim.script.tl:756
elseif type(v.genericState.optionDecision) == "string" and string_util.starts(v.genericState.optionDecision as string, "finish") then
base/content/mission/mission/mission_task_util.tl:240
if string_util.starts(keyCast, "entity_") then
… und 3 weitere Dateien.

ends(string, string) : boolean base/tealdef/scripts/string_util.d.tl:10

Aufruf: string_util.ends(…)

Hinweise

True, wenn der erste String mit dem zweiten endet (bei einem leeren Suffix immer true).

Rückgabe boolean

Im Basisspiel verwendet: 1-mal in 1 Datei

base/content/scripts/scripts/table_util.tl:24

local allowDirectComparison = allowFunctions == true or (type(key) == 'string' and string_util.ends(key as string, 'ecipe'))