CStr() 函数用于将不同数据类型的值转换为字符串类型。
用法:
CStr(val)
参数:
- val: 可能是不同数据类型的变量。
返回值:
CStr() 函数将返回一个转换后的字符串值。
程序/源代码:
下面给出了演示 CStr() 函数的源代码。给定的程序已成功编译并执行。
'VB.Net program to demonstrate the CStr() function.
Module Module1
Sub Main()
Dim str As String = ""
Dim n1 As Single = 10.25
Dim n2 As Integer = 12
Dim n3 As Double = 25.35
Dim n4 As String = "122"
str = CStr(n1)
Console.WriteLine("String value:{0}", str)
str = CStr(n2)
Console.WriteLine("String value:{0}", str)
str = CStr(n3)
Console.WriteLine("String value:{0}", str)
str = CStr(n4)
Console.WriteLine("String value:{0}", str)
End Sub
End Module
输出:
String value:10.25 String value:12 String value:25.35 String value:122 Press any key to continue . . .
说明:
在上面的程序中,我们创建了一个包含 Main() 方法的模块 Module1。在 Main() 方法中,我们创建了五个变量 str、n1、n2、n3 和 n4,它们用空字符串初始化,分别是 10.25、12、25.35 和 "122"。
str = CStr(n1) Console.WriteLine("String value:{0}", str) str = CStr(n2) Console.WriteLine("String value:{0}", str) str = CStr(n3) Console.WriteLine("String value:{0}", str) str = CStr(n4) Console.WriteLine("String value:{0}", str)
在上面的代码中,我们将指定变量的值转换为字符串值并打印在控制台屏幕上。
相关用法
- VB.NET CSByte()用法及代码示例
- VB.NET CShort()用法及代码示例
- VB.NET CSng()用法及代码示例
- VB.NET CLng()用法及代码示例
- VB.NET CInt()用法及代码示例
- VB.NET CULng()用法及代码示例
- VB.NET CDbl()用法及代码示例
- VB.NET CByte()用法及代码示例
- VB.NET CBool()用法及代码示例
- VB.NET CUShort()用法及代码示例
- VB.NET Chr()用法及代码示例
- VB.NET CDec()用法及代码示例
- VB.NET LTrim()用法及代码示例
- VB.NET DateTime FromBinary()用法及代码示例
- VB.NET RTrim()用法及代码示例
- VB.NET GetChar()用法及代码示例
- VB.NET Array Reverse()用法及代码示例
- VB.NET DateTime ToBinary()用法及代码示例
- VB.NET Array Resize()用法及代码示例
- VB.NET LCase()用法及代码示例
注:本文由纯净天空筛选整理自 VB.Net program to demonstrate the CStr() function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。