如何将字符串转换为整数,将字符串转换为double [英] How to convert a string to a integer and a string to a double

查看:154
本文介绍了如何将字符串转换为整数,将字符串转换为double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道的是如何将字符串转换为整数,将字符串转换为double。

  Dim  n,ids( 10000  As  整数 
Dim 用户( 10000 作为 字符串
Dim usertime( 10000 ),用户( 10000 作为 Double
...
使用 myreader = cmd.ExecuteReader()
while myreader.Read()
If myreader( ids)<> 然后
n = n + 1
ids(n)= CInt (myreader( ids))
user(n)= myreader( 用户名)。ToString
usertime(n)= CDbl (myreader(< span class =code-string> timer))
usertimelast(n)= CDbl (myreader( timerlast))
结束 如果
结束 while
结束 使用

解决方案

...转换示例如下。



希望它有所帮助。



  Dim  sValue 作为 字符串 
Dim dValue As Double
Dim iValue 作为 整数

sValue = 10
If Integer .TryParse(sValue,iValue))然后
Console.WriteLine( 转换为整数的值
Else
Console.WriteLine( 值未转换为整数
结束 如果

如果 Double .TryParse(sValue,dValue))那么
Console.WriteLine( 转换为Double的值
Else
Console.WriteLine( 值未转换为a双
结束 如果


All I want to know is how to convert a string to a integer and a string to a double.

Dim n, ids(10000) As Integer
Dim user(10000) As String
Dim  usertime(10000),  user(10000) As Double
     ...
     Using myreader = cmd.ExecuteReader()
          While myreader.Read()
              If myreader("ids") <> "" Then
                  n = n + 1
                  ids(n) = CInt(myreader("ids"))
                  user(n) = myreader("username").ToString
                  usertime(n) = CDbl(myreader("timer"))
                  usertimelast(n) = CDbl(myreader("timerlast"))
              End If
          End While
      End Using

解决方案

... conversion example below.

hope it helps.

Dim sValue As String
Dim dValue As Double
Dim iValue As Integer

sValue="10"
If(Integer.TryParse(sValue, iValue)) Then
    Console.WriteLine("Value converted to an Integer")
Else
    Console.WriteLine("Value NOT converted to an Integer")
End If

If(Double.TryParse(sValue, dValue)) Then
    Console.WriteLine("Value converted to a Double")
Else
    Console.WriteLine("Value NOT converted to a Double")
End If


这篇关于如何将字符串转换为整数,将字符串转换为double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆