diff --git a/.vitepress/config.ts b/.vitepress/config.ts index 249a338..7af9573 100644 --- a/.vitepress/config.ts +++ b/.vitepress/config.ts @@ -372,6 +372,7 @@ export default defineConfig({ }, { text: 'std::env', link: '/standard-library/std-env' }, { text: 'std::errors', link: '/standard-library/std-errors' }, + { text: 'std::fmt', link: '/standard-library/std-fmt' }, { text: 'std::fs', link: '/standard-library/std-fs', diff --git a/src/standard-library/std-fmt.md b/src/standard-library/std-fmt.md new file mode 100644 index 0000000..74f2a42 --- /dev/null +++ b/src/standard-library/std-fmt.md @@ -0,0 +1,19 @@ +# std::fmt + +## Functions +```jule +fn format(fmt: str, args: ...any): str +``` +It places the passes arguments in the string relative to the corresponding format string. The to_str function provided by the API is used for string conversion. Returns format string if `args.len == 0`. If the arguments have ended, the remaining part of format string is not processed and is returned as is. + +**Formatting:** + +Arguments are processed sequentially. That is, when an argument encounters a format string parameter, it will be processed according to how many parameters it is. The 5th parameter uses the 5th argument as the value. + +Each format parameter is represented as `{}` in the format string. These parameters will then be deleted according to the processing algorithm and replaced with arguments. + +**Examples:** + +- `format("{} {}!", "Hello", "World")` = `"Hello World!"` +- `format("{} {}")` = `"{} {}"` +- `format("{} is the {}", "PI Number")` = `"PI Number is the {}"` \ No newline at end of file