Top

String

There are 3 ways to declare a string: | Symbol | Special instructions | Example | |:-:|:-:|:-:| | Single quotes || The number of characters in single quotes cannot be 1 , Can't wrap | "or 'Hello World' | | double quotes" | can't wrap | "Hello" | | backquotes (float) \ | can wrap, you can use $ {} to concatenate variables or expressions | name = \World `; print (\ Hello $ (name) \)

Example

// When there is only one character in single quotes, it will be declared as type rune (int32) instead of string type print (type ('a'), 'a') // output int32, a print (type ('aa'), 'aa') // output string, aa // backticks` is very suitable for multi-line or need to splice variables print ( `This is the first line This is the second line This is the third line` ) name = 'zwr' age = 26 print (` Name: $ (name) Last year $ (age-1) year`)

Built-in objects

| Name | Description | Example | |:-:|:-:|:-:| len / length | Get the number of bytes | "Hello" .len // 6 rlen / slen / strlen | Get the number of characters | "Hello" .strlen // 2 bytes | Get the byte array | "You". bytes // output base64 runes / chars of byte array | get character array | "you" .chars // [20320] i / int | convert to integer | "10" .i + 3 // 13 f / float | convert Into floating point type | "3.14" .f / 2 // 1.57

built-in method

| name | description | example | |:-:|:-:|:-:| find | find, can be regular | '2019 12 19th'.find (\ \\ d {1,} \) // ["2019", "12", "19"] findall | Regular search for matching details | '2019Y 12M 19d'.findall(`(\d{1,})(.)`) // [["2019Y", "2019", "Y"], ["12M", "12", "M"], ["19d", "19", "d"]] contains | contains, can be regular (the second parameter true is to open regular) | "abc" .contains ("bc"); "abc1" .contains (\ \ d \,true) test | Check for regularity | "aaa" .test (\ \\ w \\ w \\ w \) split | split, can be regular | "a1b2c3d" .split (\ \\ d \) indexOf | Find characters from left to right, return -1 when not found | "abc" .indexOf ("b") lastIndexOf | Look for characters from right to left | "abc" .indexOf ("b") trim | Remove blank characters at the beginning and end | "abc" .trim () toLowerCase | Convert to lower case | "ABC" .toLowerCase () toUpperCase | Convert to uppercase | "abc" .toUpperCase () substring | Intercept part of the string | "abc" .substring (1,2) charCodeAt | Get a rune value of a bit | "Hello" .charCodeAt (1) startsWith | Does it start with a string | "abc" .startsWith ("a") endsWith | Does it end with a string | "abc" .endsWith ("a") replace | Replace, can be regular | "a1b22c" .replace (\ \\ d \, 'xxx') join | Splice an array together | "-" .join ('you', 'ok', 'ah')