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 7 years ago.
Improve this question
I need to trim the trailing spaces at the start and end in this int array and how can I do it, also I am not getting Trim() function anywhere here. Pls suggest me.
int[] arrPCT = dtOld.AsEnumerable().Select(r => r.Field<int>("PCT")).ToArray();
int are numeric values. They don't contain spaces (or any other char). It makes no sense trying to trim them.
int[] arrPCT = dtOld.AsEnumerable().Select(r => r.Field<int>("PCT").Trim()).ToArray();
If r.Field("PCT") value is of string type.
Related
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 1 year ago.
Improve this question
For a given decimal with precision of 8 like 0.00010000, I would like to get the decimal places without the trailing zeros.
All methods that I tested returned 8, and in this case should be 4.
You can use string value=decimalValue.ToString("0.########") this will convert the value into a string and show up to 8 decimal places, without trailing zeros. Eg. 1.05000000 - > 1.05, 1.00000001->1.00000001. Then value.Split('.').ToList().ElementAt(1).Length
string output = Regex.Replace("0.00010000", #"[0]*$", "");
decimal someDecimal = 0.00010000000m;
Console.WriteLine(someDecimal.ToString().TrimEnd('0'));
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 3 years ago.
Improve this question
I want to create a GUI in C#. In this GUI, I have a single text field and when I fill this text field, I would like to see how many Upped-case, Lower-case and special characters are used.
About upper and lower take a look this.
int upperCasecount = s.Count(c => char.IsUpper(c));
int lowerCaseCount = s.Count(c => char.IsLower(c));
This is for the case of special characters count.
int numOfSpecialChar = s.Count(c => !char.IsLetterOrDigit(c));
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 7 years ago.
Improve this question
I have a string that I am grabbing that is input as:
05/22/2015
Eligibility
05/06/2015
Date of Death
I need 05/06/2015. The dates will change as the program runs through a database, and I am just a little unsure on how to always be grabbing the correct one.
So you need the second date only? Is it always going to be the 3rd line? If so you can do
var secondDate = myData.Split(new [] { Environment.NewLine }, StringSplitOptions.None)[2];
If the new line isn't for certain; /n vs /r/n, use:
var secondDate = myDate.Split(Environment.Newline.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[2];
If I understand you correctly, your string has 4 lines and you want the part of the string between linebreak 2 and 3.
Search for the positions of the second and third linebreak \n and use the substring derived of these positions.
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 want convert 1,2,3,4,5,6,7,8,9,10 String to Double.
I tried Convert.ToDouble(String); and Double.Parse(String); but returned 1.0
How to convert multi comma string to double?
Thanks for help.
From the looks of your question you actually have 10 numbers not 1. Use this code:
var nums = "1,2,3,4,5,6,7,8,9,10";
var digits = nums.Split(',').Select(r => Convert.ToDouble(r)).ToArray();
// the result will be an array of doubles, also this only works with .NET 3.5 or better.
Let me know if this works for you.
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
How do i create a six digit sequence number in c# ?
Is there any other way than storing a string in the database like "000000" and later on incrementing it through the last inserted value ?
Use a plain old number as a sequence, this is what your DB will provide. If you want to display it with six digits, just call: yourNumber.ToString("D6")
(see docs)