Click here to Skip to main content
15,885,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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,
Posted

Use the following code

C#
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;
 
Share this answer
 
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,
 
Share this answer
 
Comments
Mas11 31-Jan-13 7:34am    
Dear its very common error. If u r not aware of that then there is no means to blame Mantu !. First read data type properly then ask such kind of basic question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900