fluffos/docs/efun/strings/sscanf.md
Yucong Sun c914f03d66
Add local search and documentation guide for docs site (#1221)
* docs: add local full-text search and a contributor README

Add @easyops-cn/docusaurus-search-local to the Docusaurus site so the
docs get an offline search bar (index built at build time, no external
service). English and zh-CN pages are both indexed, and matched terms
are highlighted on the target page.

Add docs/README.md describing the Docusaurus setup, local dev/build
commands, search behavior, directory layout, and gotchas; exclude it
from the published site alongside CLAUDE.md. Point the root README's
docs/ entry at it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TSzcESzU9947zkGzQ6SMmE

* docs: remove dead framework leftovers, fix index generation, complete the nav

Delete the VitePress (.vitepress/) and Jekyll (_layouts/, css/) leftovers,
the one-shot migration scripts (fix_md_header.py, fix_seealso.py), and the
stale keywords.json snapshot; prune the matching .gitignore entries and
docusaurus exclude patterns.

Rewrite gen_index.py for Docusaurus: it emitted dead .html links and
legacy 'layout: doc' frontmatter, choked on non-markdown entries, and
dropped nested categories — regenerating an index would have broken it.
It now emits the extension-less links the site actually uses, links
nested category indexes (restoring apply/* on the zh-CN index), and
refuses to run on the docs root. Fix update_index.sh's copy-paste titles
(zh-CN efun/build were titled 'APPLY'), stop it clobbering the
hand-written lpc/index.md, and cover cli/. Regenerated indexes pick up
the missing driver/ffi-plan entry. add_missing_efuns.py now takes the
keywords.json path as an argument instead of requiring a stale copy.

Move CNAME and the Google site-verification file into static/ so they
actually reach the published build output.

Complete the sidebar: link the CLI category to cli/index and add the
missing portbind/symbol/generate_keywords pages, and expose the
previously orphaned stdlib section under Reference.

Promote onBrokenLinks to 'throw' now the build is warning-free, and drop
the empty Demo section from the landing page.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TSzcESzU9947zkGzQ6SMmE

* docs: strip legacy 'layout: doc' frontmatter from all pages

Mechanical sweep removing the Jekyll-era 'layout: doc' line from every
doc page's frontmatter (Docusaurus ignores it), and the matching line
from the templates in docs/CLAUDE.md so new pages don't reintroduce it.
No content changes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TSzcESzU9947zkGzQ6SMmE

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-09 22:09:55 -04:00

2.9 KiB

title
strings / sscanf

sscanf

NAME

sscanf() - match substrings in a string.

SYNOPSIS

int sscanf( string input, string fmt, ... );

DESCRIPTION

Parse a string 'input' using the string format 'fmt', which can contain
words separated by specifiers.  Every specifier corresponds to a match-
ing function argument passed into  sscanf()  after the string 'fmt', in
order of appearance and assigning the matched values By Reference.  The
number of specifiers included in 'fmt' should match the number of func-
tion arguments included after string 'fmt'.

Specifiers:
    %s          -   match a string
    %d          -   match an integer
    %f          -   match a float
    %x          -   match a base 16 number and convert to base 10
    %(regexp)   -   match a regexp pattern

The "*" may be used in a specifier (e.g. "%*s") to skip over a match in
the input string and not assign it to a function argument.   A "%%" may
be used to match the "%" character,  which will also be skipped over in
the function arguments.

The LPC sscanf() is similar to its C counterpart however it does behave
somewhat differently.  It is not necessary or possible to pass the add-
ress of  variables into sscanf  (simply pass the name of the variable).

Another difference is that  in the LPC  sscanf(),  sscanf(str, "%s %s",
str1, str2)  will parse the  first word in  str into str1  and the rem-
ainder of str into str2.

The "%s" specifier can match an empty string, which can be an undesired
result.  sscanf(" ", "%s %s", str1, str2)  will return 2, with str1 and
str2 being assigned an "" empty string.

RETURN VALUES

The number of matched specifiers is returned.

All matched specifiers are assigned  By Reference to function arguments
included after string 'fmt', in order of appearance.

EXAMPLE

Basic Usage:
    string what, who;
    
    if (sscanf(input, "give %s to %s", what, who) == 2)
        write("You give " + what + " to " + who + ".");
    else
        write("Give what to who?");

    sscanf("give", "give %s to %s", what, who) == 0
    what == UNDEFINED && who == UNDEFINED

    sscanf("give item", "give %s to %s", what, who) == 1
    what == "item" && who == UNDEFINED

    sscanf("give item to name", "give %s to %s", what, who) == 2
    what == "item" && who == "name"

Numeric:
    int i;
    sscanf("123", "%d", i) == 1
    i == 123

    float f;
    sscanf("1.23", "%f", f) == 1
    f == 1.230000

    int b10;
    sscanf("ABC", "%x", b10) == 1
    b10 == 2748

Regexp:
    string str1, str2;
    sscanf("one two", "%([a-z]+) %([a-z]+)", str1, str2) == 2
    str1 == "one" && str2 == "two"

SEE ALSO

explode(3), pcre_extract(3), regexp(3), replace_string(3), strsrch(3)