Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm reading an email and performing a few operations.
In email it can't be in defined format as below,
Email formats:
Hi Team,
Please create 7025-45-365-14, 9851-98-524-12
5741-55-452-45
Thanks
MailItem.Body = "Hi Team,\r\n\r\n \r\n\r\nPlease create 7025-45-365-14, 9851-98-524-12\r\n\r\n5741-55-452-45.\r\n\r\n \r\n\r\nThanks\r\n"
My goal is to exact only the string parts into a loop one by one as below,
1st loop > 7025-45-365-14
2nd loop > 9851-98-524-12
3rd loop > 5741-55-452-45
I tried various logic but I can't extract as I need. Can someone help me?
To extract digits in that pattern (4-2-3-2)
foreach (var m in new Regex(#"\b(\d{4}-\d{2}-\d{3}-\d{2})\b").Matches(mail))
Console.WriteLine(m.Value);
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
So I made a simple c# file reader because I was bored and added an if statement to filter the results. But when I ran it, it gave me more results than I wanted. I was supposed to get
276, 2, and there was only one line inside the file with that value, but I got multiple. I checked the file and it had lines ending with the same value. I tried string.Equals(line, "276, 2") but it gave me the same results. I doubt there isn't something in c# that doesn't solve this issue.
You can use Regex, as it's mentioned in this issue
bool result = Regex.IsMatch(line, "\\b276, 2\\b");
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I want to clear just birkatmankontur list but this code clears all lists in my program
katmankonturlari.Add(ii, birkatmankontur);
katmankonturlari.ToList();
birkatmankontur.Clear();
You probably want something like this:
// Create a shallow copy of birkatmankontur and add it into katmankonturlari
katmankonturlari.Add(ii, birkatmankontur.ToList());
// Clear original birkatmankontur;
// note, that katmankonturlari contains birkatmankontur's copy
birkatmankontur.Clear();
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
The application that I've made I've got a text box called service cost. This allows the user to enter the cost of the service they have provided and this is decimal. I'm trying to get this service cost displayed in a DGV, I've got everything else working apart from this.
currentComputer.ServiceCost = Convert.ToDecimal(txtServiceCost);
The above is the code that I currently have, is there something wrong that I've done here?
From the question it is clear that txtServiceCost is the TextBox, and Convert.ToDecimal() expects a string as input so you should use txtServiceCost.Text instead for txtServiceCost. Since txtServiceCost is a control where as txtServiceCost.Text is a string
currentComputer.ServiceCost = Convert.ToDecimal(txtServiceCost.Text);
But i would like to suggest you to use decimal.TryParse
decimal userInput;
if (!decimal.TryParse(txtServiceCost.Text, out userInput))
{
// Throw some warning here that invalid input
}
currentComputer.ServiceCost = userInput;
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have the following regex pattern:
-?\d+(?:\.\d+)?%
Which works really well to match percentages. Now what I need is to be able to get the numerical value of this in a group.
I have tried the following:
(?<percentage>-?\d+(?:\.\d+)?)%
(?<percentage>-?\d+(\.\d+)?)%
(?<percentage>(-?\d+(?:\.\d+)?))%
(?<percentage>(-?\d+(\.\d+)?))%
None of them work and I only get the integer part of the percentile.
How can this be accomplished?
The correct regex is:
(?<percentage>-?(?:\d*\.?\d+|\d+\.?\d*))%
I tried the following examples and they all seemed to work (using the first regex that you tried):
Regex.Match("12%", #"(?<percentage>-?\d+(?:\.\d+)?)%").Groups["percentage"].Value
// 12
Regex.Match("12.345%", #"(?<percentage>-?\d+(?:\.\d+)?)%").Groups["percentage"].Value
// 12.345
Regex.Match("-12.345%", #"(?<percentage>-?\d+(?:\.\d+)?)%").Groups["percentage"].Value
// -12.345
You might note the use of the "#" in front of the regular expression string - maybe that is the issue you are having.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am generating multiple CSV's in a folder ,I have to merge all of them and make one file.
P.s.
1.They all will have same headers.
2.Their names are not fixed and will be changed every other day acc to date and some other parameters.
Not really tested but should give you an idea:
var allCsv = Directory.EnumerateFiles("Src-Path", ".*csv", SearchOption.TopDirectoryOnly);
string[] header = { File.ReadLines(allCsv.First()).First(l => !string.IsNullOrWhiteSpace(l)) };
var mergedData = allCsv
.SelectMany(csv => File.ReadLines(csv)
.SkipWhile(l => string.IsNullOrWhiteSpace(l)).Skip(1)); // skip header of each file
File.WriteAllLines("Dest-Path", header.Concat(mergedData));
Note that you have to add using System.Linq;