github.com/GuanceCloud/cliutils@v1.1.21/pipeline/ptinput/funcs/md/parse_int.en.md (about) 1 ### `parse_int()` {#fn-parse-int} 2 3 Function prototype: `fn parse_int(val: int, base: int) str` 4 5 Function description: Converts the string representation of a numeric value to a numeric value. 6 7 Function parameters: 8 9 - `val`: The string to be converted. 10 - `base`: Base, the range is 0, or 2 to 36; when the value is 0, the base is judged according to the string prefix. 11 12 Example: 13 14 ```python 15 # script0 16 a = "7665324064912355185" 17 b = format_int(parse_int(a, 10), 16) 18 if b != "6a60b39fd95aaf71" { 19 add_key(abc, b) 20 } else { 21 add_key(abc, "ok") 22 } 23 24 # result 25 ''' 26 { 27 "abc": "ok" 28 } 29 ''' 30 31 # script1 32 a = "6a60b39fd95aaf71" 33 b = parse_int(a, 16) # base 16 34 if b != 7665324064912355185 { 35 add_key(abc, b) 36 } else { 37 add_key(abc, "ok") 38 } 39 40 # result 41 ''' 42 { 43 "abc": "ok" 44 } 45 ''' 46 47 48 # script2 49 a = "0x6a60b39fd95aaf71" 50 b = parse_int(a, 0) # the true base is implied by the string's 51 if b != 7665324064912355185 { 52 add_key(abc, b) 53 } else { 54 c = format_int(b, 16) 55 if "0x"+c != a { 56 add_key(abc, c) 57 } else { 58 add_key(abc, "ok") 59 } 60 } 61 62 63 # result 64 ''' 65 { 66 "abc": "ok" 67 } 68 ''' 69 ```