Wiki source for KeyPgValint


Show raw source

{{fbdoc item="title" value="VALINT"}}----
Converts a string to a 32bit integer

{{fbdoc item="syntax"}}##
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Valint** ( [[KeyPgByref|byref]] //strnum// [[KeyPgAs|as]] [[KeyPgConstQualifier|const]] [[KeyPgString|string]] ) [[KeyPgAs|as]] [[KeyPgLong|long]]
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Valint** ( [[KeyPgByref|byref]] //strnum// [[KeyPgAs|as]] [[KeyPgConstQualifier|const]] [[KeyPgWstring|wstring]] ) [[KeyPgAs|as]] [[KeyPgLong|long]]
##
{{fbdoc item="usage"}}##
//result// = **Valint** ( //strnum// )
##
{{fbdoc item="param"}}
##//strnum//##
the string to convert

{{fbdoc item="ret"}}
Returns a ##[[KeyPgLong|Long]]## value of the converted string

If the first character of the string is invalid, ##**Valint**## will return ##0##.

{{fbdoc item="desc"}}
For example, ##**Valint**("10")## will return ##10##, and ##**Valint**("10.60")## will return ##10## as well. The function parses the string from the left, skipping any white space, and returns the longest number it can read, stopping at the first non-suitable character it finds. Any non-numeric characters, including decimal points and exponent specifiers, are considered non-suitable, for example, ##**Valint**("23.1E+6")## will just return ##23##.

##**Valint**## can be used to convert integer numbers in [[KeyPgBin|binary]] / [[KeyPgOct|octal]] / [[KeyPgHex|hexadecimal]] format, if they have the relevant identifier (##"&B"## / ##"&O"## / ##"&H"##) prefixed, for example: ##**Valint**("&HFF")## returns ##255##.

If you want to convert a number into string format, use the ##[[KeyPgStr|Str]]## function.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/strings/valint.bas"}}%%(freebasic)
dim a as string, b as integer
a = "20xa211"
b = valint(a)
print a, b
%%

%%
20xa211 20
%%


{{fbdoc item="lang"}}
- Not available in the //[[CompilerOptlang|-lang qb]]// dialect unless referenced with the alias ##**""__Valint""**##.

{{fbdoc item="diff"}}
- New to ""FreeBASIC""

{{fbdoc item="see"}}
- ##[[KeyPgClng|Clng]]##
- ##[[KeyPgVal|Val]]##
- ##[[KeyPgValuint|Valuint]]##
- ##[[KeyPgVallng|Vallng]]##
- ##[[KeyPgStr|Str]]##
- ##[[KeyPgChr|Chr]]##
- ##[[KeyPgAsc|Asc]]##

{{fbdoc item="back" value="CatPgCasting|Converting Data Types"}}{{fbdoc item="back" value="CatPgString|String Functions"}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode