Skip to content

STR


返回数字、布尔值或 Unicode 字符字符串的字符串表示形式

语法

vb
declare function Str ( byval n as byte ) as string
declare function Str ( byval n as ubyte ) as string
declare function Str ( byval n as short ) as string
declare function Str ( byval n as ushort ) as string
declare function Str ( byval n as long ) as string
declare function Str ( byval n as ulong ) as string
declare function Str ( byval n as longint ) as string
declare function Str ( byval n as ulongint ) as string
declare function Str ( byval n as single ) as string
declare function Str ( byval n as double ) as string
declare function Str ( byval b as boolean ) as string
declare function Str ( byref str as const string ) as string
declare function Str ( byval str as const wstring ) as string

用法

result = Str[$]( number )

or

result = Str( string )

参数

number

要转换为字符串的数值表达式。

string

要转换为字符串的字符串表达式。

说明

Str 将数值变量转换为其字符串表示形式。这样使用时,它等价于应用于数值变量的 WstrString 版本,与 Val 函数相反(Val 函数将字符串转换为数字)。

Str 将布尔变量转换为其字符串表示形式 "false" / "true"。

Str 也将 Unicode 字符字符串转换为 ASCII 字符字符串。这样使用时,它与 Wstr 的功能相反。如果给定 ASCII 字符字符串,则不加修改地返回该字符串。

示例

start GeSHi

vb
Dim a As Integer
Dim b As String
a = 8421
b = Str(a)
Print a, b

end GeSHi

方言差异

  • -lang qb 方言中,Str 会在正数左侧填充一个空格。
  • -lang qb 方言中,字符串类型后缀 "$" 是必需的。
  • -lang fblite 方言中,字符串类型后缀 "$" 是可选的。
  • -lang fb 方言中,字符串类型后缀 "$" 会被忽略,仅在使用 -w suffix 编译选项(或 -w pedantic 编译选项)时才会给出警告。

平台差异

  • FreeBASIC 的 DOS 版本/目标不支持 Str 的宽字符字符串版本。

与 QB 的区别

  • QB 不支持 Str 的宽字符字符串版本。

另请参阅

  • Val
  • Cbool
  • Chr
  • Asc

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系