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
I have some strings, like below
a1
c1
b0
I want to sort them to a1b0c1
I tried the code below:
string answer1 = new string(answer.OrderBy(c => c).ToArray());
But the result is 011abc
How to make the string a1b0c1?
I assume, you have one string consisting of several lines. You have to split your string into an array, sort this and join the lines together:
string input = "a1\nc1\nb0";
string[] lines = input.Split('\n');
string result = string.Join("\n", lines.OrderBy(x => x));
Online demo: https://dotnetfiddle.net/u32Pk9
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 2 years ago.
Improve this question
sb.Qualilfication_Master.First().Qual_List contain string values like "B.C.A,M.C.A,B.B.A"
and txtQualification.text contain string like "B.C.A, M.Com"
I want match above two thing
var sendnoti = (from p in db.Reg_JobSeeker_Masters where p.Qualification_Masters.First().Qual_List.Contains(txtQualification.Text)select p).ToList();
If I'm reading this right - and you want to find the strings that are common to two lists - then you can just use the intersect method.
I am just assuming txtQualification.Text is a List<string> so in that case you could just right it like this -
var sendnoti = (from p in db.Reg_JobSeeker_Masters where p.Qualification_Masters.First().Qual_List.Any(ql => txtQualification.Text.Contains(ql))select p).ToList();
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 need a c# function that takes a string:
Input: "str1__value__xyz__str4__"
I want to convert it to an array (or list) of string
Output: string[] output = { str1, value, xyz, str4}
I think we can use Linq or a regular expression.
Input.Split(new string[] { "__" }, StringSplitOptions.None);
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 data:
1,1,1,1,1,1
I want to read that line and covert it into array of ints or some other type.
Is there a one line solution to do that?
var arr = "1,1,1,1,1,1".Split(',').Select(s => int.Parse(s)).ToArray();
In case your text includes some spaces
var arr = Regex.Matches("1,1,1,1,1,1", #"\d+")
.Cast<Match>()
.Select(m => m.Value)
.ToArray();
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
Which is the best way I can compare two C# string variables containing comma separated values and find the difference?
The scenario is like.
string variable1 = "AAA, BBB, CCC, DDD";
string variable2 = "AAA, CCC, DDD, EEE";
And I need the result like "BBB" (the value which is present in variable2 but not in variable1.
Thanks
Use Except:-
var result = variable1.Split(new char[] {','})
.Except(variable2.Split(new char[] {','})).ToArray();
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I've an array of strings below and wanted to format like the followings, what is the best way of doing that? Thanks in advance.
line[0] = "This is line one two tree";
line[1] = "This is Abc Cde";
line[2] = "This is cjdj";
I want it to format to display like this
This is line one two tree
This is Abc Cde..........
This is cjdj.............
You can use the string.PadRight() method, coupled with determining which of the array of strings is the widest:
var width = line.Max(l => l.Length);
foreach (var l in line)
Console.WriteLine(l.PadRight(width, '.'));
You could use:
var output = string.Join(Environment.NewLine, line.Select(l => l.PadRight(line[0].Length, '-').ToArray());
Use string.PadRight to pad each string, up to the specified length, with instances of a specified character.
Use PadRight:
http://msdn.microsoft.com/en-us/library/system.string.padright.aspx
e.g.
int len = line[0].Length;
Console.WriteLine(line[0]);
Console.WriteLine(line[1].PadRight(len,"."));
Console.WriteLine(line[2].PadRight(len,"."));