Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How to write a regular expression to scan whether input is a signed decimal or not?
e.g:
-1.234567
-.1234567
123456789
1.2345678
1234567.8
-1234.567
Input length must be 9.
Why are you using RegEx? There are better methods to determine if a string is signed or not.
Use decimal.TryParse() and Math.Sign() to get your answer.
string input = "-1.2342";
decimal decValue;
bool isDecimal = decimal.TryParse(input, out decValue);
if (isDecimal)
{
int signValue = Math.Sign(decValue);
}
else
{
throw new Exception("Not a valid decimal!");
}
You could do it the hard way:
([-\d]\d\.\d\d\d\d\d\d|[-\d]\d\d\.\d\d\d\d\d|[-\d]\d\d.\d\d\d\d|...)
Basically this is any of the forms you listed OR-ed. This is quite tedious, but right now I can't think of any other way that will work for all possible inputs.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to generate number as format above and I try to use UUID() and GUID() but it is not what I want(difference format and it is hexadecimal not number)
anyone have any idea or logic to do it?
The simplest way to generate 1000000000000 unique numbers is just an ever-increasing sequence:
long i = 42; // whatever
string key = $"{i / 100000000:0000}-{(i / 10000) % 10000:0000}-{i % 10000:0000}";
The next time, increase i before generating the key.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have decimal values in the database. I want to show the decimal value in it. How to convert decimal values into it.
int vatprice;
dt.Load(cmd.ExecuteReader());
vatprice = Convert.ToInt32(dt.Rows[0][5].ToString());//getting error here
As per your requirement, round decimal up to 2 place using following way :
1) Use Math.Round().
var vatprice= Convert.ToDecimal(Math.Round(dt.Rows[0][5], 2));
2) second way is
var vatprice=Convert.ToDecimal(dt.Rows[0][5].ToString ("#.##"));
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have to validate a sting with regular expression.
String Should be in the NHCC-XXXXX-00 Format ,where X is a Number.
Correct strings:
NHCC-10010-00,
NHCC-78965-00,
NHCC-99654-00
Wrong strings:
NHCC-1001-00
NHCC-78965-0
NHC-99654-00
ASDF-99654-00
NHCC-F9654-00
NHCC-99654-01
Can any one help me to solve the above senario?
This should work:
"NHCC-\d{5}-00"
Demo
You need to use anchors inorder to do an exact match.
#"^NHCC-\d{5}-00$"
The regular expression you want is #"(?s)^NHCC-\d{5}-00$"
if (!Regex.IsMatch(input, #"(?s)^NHCC-\d{5}-00$"))
{
//not valid
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a string like below
he/a0h/a0dv/a0jks
I would like to be string become as below.
hehdvjks
Need to remove the "/a0" from the string.
The String.Replace method is what you're looking for, just do a;
String myString = "he/a0h/a0dv/a0jks"
myString = myString.Replace("/a0", "")
It'll return a modified 'myString' with all occurrences of the old value ("/a0") replaced with a new value (blank in this case).
The MSDN reference for String.Replace can be found at:
http://msdn.microsoft.com/en-us/library/fk49wtc1%28v=vs.110%29.aspx
var result = "he/a0h/a0dv/a0jks".Replace("/a0", string.Empty);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I don't understand what is wrong i did the same code with the insert and run well
Entity obj = new Entity();
.
.
.
obj.DEPID = decimal.Parse(((TextBox)GridView1.FooterRow.FindControl("txtDEPID")).Text);
myFactory.UpdateObject(obj);
The value that is returned by the
((TextBox)GridView1.FooterRow.FindControl("txtDEPID")).Text
Is not a decimal-like string. It contains some other Special Characters like alphabets etc.
While passing the values, you need to make sure that the values being passed match the values required. Check what is the value of this.
txtDEPID.Text;
Use it in a MessageBox, to check for the value. I'm sure there is some sort of non decimal part in the string. Which is causing the trouble while converting the String to Decimal.
MessageBox.Show(txtDEPID.Text);