相关疑难解决方法(0)

ValueError:基数为10的int()的无效文字:'\n'

我正在寻找我的特定代码的错误答案.我搜查了其他人,他们仍然很混乱.

我不确定为什么会这样.

以下是错误引用的代码部分,后跟错误.

def processScores( file, score):
#opens file using with method, reads each line with a for loop. If content in line
#agrees with parameters in  if statements, executes code in if statment. Otherwise, ignores line    

    with open(file,'r') as f:
        for line in f:  #starts for loop for all if statements
            if line[0].isdigit: 
                start = int(line) 
                score.initialScore(start) #checks if first line is a number if it is adds it to intial score
Run Code Online (Sandbox Code Playgroud)

我收到的错误消息:

    Traceback (most recent call last):
  File …
Run Code Online (Sandbox Code Playgroud)

python

1
推荐指数
1
解决办法
2万
查看次数

如何检查输入包含文本

可能重复:
创建仅接受数字的WPF TextBox

我如何检查文本框中的输入值是否包含文本?我想用户只输入数字谢谢

c# wpf

0
推荐指数
1
解决办法
621
查看次数

如何验证,使用正则表达式,字符串中的所有字符都是数字?

如何验证字符串中的每个字符是否为0-9位?例如:1343151234234有效但2342343ABC34234无效.谢谢.

regex

0
推荐指数
1
解决办法
73
查看次数

使用Regex检查字符串

我有一个textBox在我的程序包含string有以满足一些要求.我问这个问题是找出满足这些要求的最佳方法.

string不可能NullOrEmpty,它必须完全由整数组成.该string还可以包含空格,这是我的症结所在,因为空间是不是整数.

这就是我正在使用的(我知道它目前可能有点多余):

//I test the string whenever the textBox loses focus
private void messageBox_LostFocus(object sender, RoutedEventArgs e)
{
      if (string.IsNullOrEmpty(TextBox.Text))
          ButtonEnabled = true;
      else if (Regex.IsMatch(TextBox.Text, @"^\d+$") == false)
      {
          //I think my problem is here, the second part of the if statement doesn't
          //really seem to work because it accepts characters if there is a space
          //in the string.
          if (TextBox.Text.Contains(" ") && !Regex.IsMatch(TextBox.Text, @"^\d+$"))
              ButtonEnabled = true; …
Run Code Online (Sandbox Code Playgroud)

c# regex string wpf textbox

0
推荐指数
1
解决办法
321
查看次数

验证用户输入的电话号码,Int到大c#的问题

项目概述:

我正在创建一个多表单应用程序,它由两个表单和一个父类组成.两者Forms都有一系列验证功能,例如isLetter() isNumber()isValidEmail().使用isNumber()函数时出现了我的问题.

public static bool numValidation(string strNum)
        {
            if (!string.IsNullOrWhiteSpace(strNum))
            {
                int temp;
                if (int.TryParse(strNum, out temp))
                {
                    Console.WriteLine("Phone Number is a valid input: " + temp);
                    return true;
                }
                else
                { Console.WriteLine(temp + "Is not Valid input!!"); }
            }
            return false;
        }
Run Code Online (Sandbox Code Playgroud)

乍一看它工作正常,但一旦我试图打破它,我意识到当输入一个实际的电话号码时,我得到一个错误,说这个数字太高了.任何想法如何绕过这个约束?因为我需要这个验证的唯一原因是电话号码,传真等.我只需要这个功能来接受非常大的数字,如电话号码

.net c# winforms

0
推荐指数
1
解决办法
32
查看次数

检查字符串仅包含数字

如何检查字符串是否为数字.我正在验证手机号码,它应该有10位数字,并且只能采用数字格式.

string str="9848768447"
if(str.Length==10 &&  Here I need condition to check string is number or not)
{
 //Code goes here
}
Run Code Online (Sandbox Code Playgroud)

我是编程新手.请帮我

c#

-3
推荐指数
1
解决办法
3506
查看次数

标签 统计

c# ×4

regex ×2

wpf ×2

.net ×1

python ×1

string ×1

textbox ×1

winforms ×1