最后显示数字肯定 [英] Displaying Numbers at last for sure
问题描述
亲爱的论坛,
我对这类概念有些新意.......其实赞成我需要的是当我在QLineEdit中给出一些值时,如果它不包含数字它应该至少有四位数它应该引发错误......希望你能得到我...... Actualy我有在Java中完成相同的工作并且它工作正常......请找到供您参考的代码......任何解决方案都会很明显.....在此先感谢.....
[代码]
公共课堂考试{
public static void main(String [] args){
String s =abcd1000231231232131212;
System.out.println(check(s));
}
public static boolean check(String s){
if(s.length()> = 4){
String s1 = s.substring(s.length() - 4,s.length());
System.out.println(s1);
试试{
Inte ger.parseInt(s1);
if(Integer.parseInt(s1)== 0){
返回false;
}
返回true;
} catch(NumberFormatException e){
返回false;
}
}
返回false;
}
}
[/ code]
问候,
使用以下代码
string s1 = GHGHGHJJH1238;
int x = Int32 .Parse(s1.Substring(s1.Length) - 4 , 4 ));
MessageBox.Show(x.ToString()); // 显示消息或任何你想要的内容
好运;
亲爱的Mantu,
感谢您的回复......您认为您发送的代码如何运作......实际上它的抛出错误如
---->''Int32''未在此范围内声明
----> ;''class QString''没有名为''Substring''的成员'
---->''class QString''没有名为''的成员长度''
---->请求''x'中的成员''ToString'',这是非类型''int ''
实际上SubString不支持donno为什么.........任何解决方案都会很明显.....在此先感谢...
问候,
Dear Forums,
I am somewhat new to this type of concept.......Actually the favour that i need is when i give some value in the QLineEdit at the end it should have atleast four digits if it doesn''t contain digits it should raise an error......hope you got me....Actualy i have done the same in Java and it works fine......Please find the code for your reference......Any solution would be appreciable.....Thanks in Advance.....
[code]
public class test {
public static void main(String[] args) {
String s = "abcd1000231231232131212";
System.out.println(check(s));
}
public static boolean check(String s ) {
if(s.length()>=4){
String s1 = s.substring(s.length()-4, s.length());
System.out.println(s1);
try {
Integer.parseInt(s1);
if(Integer.parseInt(s1) == 0){
return false;
}
return true;
} catch (NumberFormatException e) {
return false;
}
}
return false;
}
}
[/code]
Regards,
Use the following code
string s1 = "GHGHGHJJH1238"; int x = Int32.Parse(s1.Substring(s1.Length - 4, 4)); MessageBox.Show(x.ToString());// show message or whatever you want
Best of luck;
Dear Mantu,
Thanks for the reply......How do you think the code that you sent will work....Actually its throwing errors like
---->''Int32'' was not declared in this scope
---->''class QString'' has no member named ''Substring''
---->''class QString'' has no member named ''Length''
---->request for member ''ToString'' in ''x'', which is of non-class type ''int''
Actually SubString is not supporting donno why.........Any solution would be appreciable.....Thanks in Advance...
Regards,
这篇关于最后显示数字肯定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!