如何将整数转换为任何字符串vb [英] How do i convert an integer to any string vb

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

问题描述

您好,我一直在花费大部分时间试图弄清楚如何正确地从整数转换为字符串;所以我可以添加一个循环,如果你输入一个字母而不是一个数字,你必须重新输入。数字而不是崩溃。如果有人能指出我正确的方向,我将不胜感激。



我尝试过:



我已尝试过这条线:

 Score = Console.ReadLine()得分=  CStr (得分)

解决方案

读取它作为字符串,然后使用Integer.TryParse转换它:

  Dim  x  As  整数 
如果 整数 .TryParse(stringFromUser,x)然后
' 向用户报告问题。
返回
结束 如果


Hello, I've been spending most of the day trying to figure out how to properly convert from an integer to a string; so I can add a loop where if you input a letter instead of a number you have to re-enter.the number instead of just crashing. If anyone can point me in the right direction it would be much appreciated.

What I have tried:

Ive tried things along this line:

Score = Console.ReadLine() Or Score = CStr(Score)

解决方案

Read it as a string, then use Integer.TryParse to convert it:

Dim x As Integer
If Not Integer.TryParse(stringFromUser, x) Then
	' report problem to user.
        Return
End If


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

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