Get all string between a string separator [closed] - c#

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);

Related

Sort a String consisting of letters and numbers [closed]

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

Regex to remove c# [closed]

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 4 years ago.
Improve this question
I want to remove some string from regex in c#.
I have a string
000603ABC140702-005051-I-FILL200-NNYYNY180319-142110-A2002.zip
From this I want to remove those strings
140702
142110
And I want a result as
000603ABC-005051-I-FILL200-NNYYNY180319--A2002.zip
How can I do that in regex?
You can use the Regex.Replace method (https://msdn.microsoft.com/en-us/library/xwewhkd1(v=vs.110).aspx).
var regex = new Regex("(140702)|(142110)");
var result = regex.Replace("000603ABC140702-005051-I-FILL200-NNYYNY180319-142110-A2002.zip", "");
Although, as already stated by #CompuChip, String.Replace would probably be more efficient in this case. There's a discussion of various methods of replacing substrings and their efficiency at https://blogs.msdn.microsoft.com/debuggingtoolbox/2008/04/02/comparing-regex-replace-string-replace-and-stringbuilder-replace-which-has-better-performance/.

Split calculator expression with binary and unary operations [closed]

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 get string input like: 1+2*5+sin100-2 and In order to calculate it I need to make array that will look like:
1,+,2,*,5,+,sin,100,-,2
Is there easy solution to do this problem?
Currently I am doing it with loop on all the chars in the string but I want to know if c# offer easiest solution to this problem.
I found easy solution. You could just write it instead of complain that there is no code in the question.
string expression;//my calculator expression
string[] operators;//array that contains both unary and binary operators.
for(int i=0;i<operators.length;i++)
{
expression = expression.replace(operators[i]," "+operators[i]+ " ");
}
string[] Values= expression.split(" ");

split user:pass to user and pass in c# [closed]

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
So basically I have this program where the user uploads a list of user:pass in that format and I need user to be in it's own string and pass to be in it's own string.
Example of what i tried
string Account = listBox1.SelectedIndex.ToString();
char[] delimiterChars = { ':' };
Account.Split(delimiterChars);
I need to get the front part of user into string user and back part into string pass
Use string.split:
var combined = "user:pass";
var split = combined.Split(new[]{":"});
var user = split[0];
var password = split[1];

Compare two comma separated string and find the missing values [closed]

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();

Categories