Morrowind Mod:XStringBuild

The UESPWiki – Your source for The Elder Scrolls since 1995
Jump to: navigation, search

A function added by MWSE.

xStringBuild returns a new string that is constructed based on the format string and any other variable values as needed. The format string is similar to those for MessageBox with % indicating some special character or variable substitution. Some patterns can be used to place special characters into the string:

%% a single % sign is placed in the string.

%n a new line marker (CR/LF) is placed in the string.

%q a " quotation mark is placed in the string.

The rest are used to insert values from the remaining parameters into the output string.

%d a short or long value is inserted as a decimal integer.

%h a short or long value is inserted as a hexadecimal integer.

%f a float value is inserted as real decimal number.

%s a string value is inserted.

%l a long value is inserted as a four character string.

The uppercase forms %N, %Q, %D, %H, %F, %S, and %L also work. The float specifier takes a precision specifier just like the MessageBox command. The format "%.3f" will print a floating point value with three digits after the decimal point. The string specifier can take two numbers in its specifier.

%2s skips the first two characters of the string, but inserts the rest.

%.3s inserts only three characters of the string.

%4.5s skips 4 characters, then inserts the next 5 characters of the string.

The compiler doesn't currently support more than 12 parameters at a time.

The format string is limited to 64 characters.

Following example outputs "Hello, World!" messagebox.

Syntax[edit]

result (string): xStringBuild format (string) ...

Example 1[edit]

long str

setx str to xStringBuild "Hello, everyone in the world! How do you do?!"
setx str to xStringBuild "%.7S %23.6S" str str
xmessagefix str
messagebox "1111111111111111111111"

Example 2[edit]

; This example removes spaces from a string. You need to do it if you are using player name in a file name. 
short match
long fileName
long string
long string1

setx match to xStringMatch fileName " "
whilex ( match )        
        setx match to xStringMatch fileName " "
        setx temp string string1 to xStringParse "%.0s %.0s" fileName
        setx fileName to xstringbuild "%s%s" string string1
endwhile

See Also[edit]

xPCCellID
xRefID
xMyCellID
xGetName
xSetName
xGetBaseID
xStringCompare
xStringLength
xStringParse
xStringMatch
xLogMessage
xMessageFix