string.format
|
MY-BASIC |
string.format(<str::format>,<str::string>) string.format(<str::format>,<int::integer>) string.format(<str::format>,<dbl::number>) |
Format a string, integer or floating value (second argument) according the format-control string (first argument).
Return value: string
Arguments
|
format |
str: Format control string with syntax: %[flags][width][.precision][length]specifier
Note that the the # symbol does not work as this will be interpreted as the comment character during reading |
||||||||||||||||||||||||||||||
|
string |
str: Substring to find in string. |
Examples
Print the total moles in the system, the phases (exchange, minerals, solid-solutions) and the aqueous phase of the primary components.
|
USER_PRINT -mybasic -start nmoles = sys("elements","count","names","types","moles")for i = 1 to countcomp = names(i)if(string.find(comp,"(") < 0) thenwrite(string.format("%-5s",comp) + string.format("%-20s"," Total (mole) ") + string.format("%18.12e",sys(comp)) + eol)write(string.format("%-5s",comp) + string.format("%-20s"," Aqueous (mole) ") + string.format("%18.12e",totmole(comp)) + eol)write(string.format("%-5s",comp) + string.format("%-20s"," Solid (mole) ") + string.format("%18.12e",sys(comp)-totmole(comp)) + eol)endifnext-end |
In a system with H, O, Ca, and Si, the user_print block in the output file is, for example,
----------------------------------User print-----------------------------------H Total (mole) 5.852226105076e+01.H Aqueous (mole) 5.552766913095e+01H Solid (mole) 2.994591919807e+00O Total (mole) 3.100037832923e+01O Aqueous (mole) 2.777352864120e+01O Solid (mole) 3.226849688032e+00Ca Total (mole) 1.119218076064e+00Ca Aqueous (mole) 9.662913359766e-03Ca Solid (mole) 1.109555162705e+00Si Total (mole) 3.100148638994e-01Si Aqueous (mole) 1.558118753008e-05Si Solid (mole) 3.099992827118e-01 |