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];
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
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
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 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
First I want to say that I'm completely new to coding and although I've learned some basics a few years ago.
For now I'm trying to make a program that searches in an user inputted text. And replace some parts of that, then gives the new text back.
Like this:
stormcloud-146919.appspot.com/purchase/listing/?global=ahNzfnN0b3JtY2xvdWQtMTQ2OTE5ckULEgNVSUQiEDEyNTA0NjQ5MDgzMjUyNDIMCxIGUGxheWVyGICAgICAgIAKDAsSDEl0ZW1JbnN0YW5jZRiAgICAgOSRCgw&coin=3&xpPlayer=10&sidekick1=ahNzfnN0b3JtY2xvdWQtMTQ2OTE5ckULEgNVSUQiEDEyNTA0NjQ5MDgzMjUyNDIMCxIGUGxheWVyGICAgICAgIAKDAsSDEl0ZW1JbnN0YW5jZRiAgICAkMmPCgw&xpSidekick1=10&sidekick2=ahNzfnN0b3JtY2xvdWQtMTQ2OTE5ckULEgNVSUQiEDEyNTA0NjQ5MDgzMjUyNDIMCxIGUGxheWVyGICAgICAgIAKDAsSDEl0ZW1JbnN0YW5jZRiAgICA0OqZCgw&xpSidekick2=10&k=ahNzfnN0b3JtY2xvdWQtMTQ2OTE5ciwLEgNVSUQiEDEyNTA0NjQ5MDgzMjUyNDIMCxIGUGxheWVyGICAgICAgIAKDA&l=ahNzfnN0b3JtY2xvdWQtMTQ2OTE5chQLEgdMaXN0aW5nGICAgID00JwKDA&
With the bold parts being searched and replaced by my custom text or digits.
I hope you are looking to update some querystring parameter values.
You can use HttpUtility.ParseQueryString() for this.
Find the sample below.
var url = "stormcloud-146919.appspot.com/purchase/listing/?global=ahNzfnN0b3JtY2xvdWQtMTQ2OTE5ckULEgNVSUQiEDEyNTA0NjQ5MDgzMjUyNDIMCxIGUGxheWVyGICAgICAgIAKDAsSDEl0ZW1JbnN0YW5jZRiAgICAgOSRCgw&coin=3&xpPlayer=10&sidekick1=ahNzfnN0b3JtY2xvdWQtMTQ2OTE5ckULEgNVSUQiEDEyNTA0NjQ5MDgzMjUyNDIMCxIGUGxheWVyGICAgICAgIAKDAsSDEl0ZW1JbnN0YW5jZRiAgICAkMmPCgw&xpSidekick1=10&sidekick2=ahNzfnN0b3JtY2xvdWQtMTQ2OTE5ckULEgNVSUQiEDEyNTA0NjQ5MDgzMjUyNDIMCxIGUGxheWVyGICAgICAgIAKDAsSDEl0ZW1JbnN0YW5jZRiAgICA0OqZCgw&xpSidekick2=10&k=ahNzfnN0b3JtY2xvdWQtMTQ2OTE5ciwLEgNVSUQiEDEyNTA0NjQ5MDgzMjUyNDIMCxIGUGxheWVyGICAgICAgIAKDA&l=ahNzfnN0b3JtY2xvdWQtMTQ2OTE5chQLEgdMaXN0aW5nGICAgID00JwKDA&";
Console.WriteLine(url);
var uriBuilder = new UriBuilder(url);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
query["coin"] = "4";
query["xpPlayer"] = "4";
query["xpSidekick1"] = "4";
query["xpSidekick2"] = "4";
uriBuilder.Query = query.ToString();
Console.WriteLine(uriBuilder.ToString());
See if that meets your requirements.
Remember to import System.Web namespace.
using System.Web;
More details on the code an be found here:
http://codeskaters.blogspot.ae/2016/12/c-update-querystring-values-in-url.html
You can use
string [] split = input.Split(new Char [] {'&'});
And the for each split .Split(new Char [] {'='});
Replace needed values and concat all parts to new string.
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 am sorry for that bad Title, but basicaly my problem is really simple. I got 1 string which is basic alphabet and the second string which is gonna be part of the alphabet (8 characters) which user will fill up by himself. If 2 characters are the same, they will get removed and then rest of characters will be in the TextBox3. could someone pls help me ?
string alphabet = "abcdefghijklmnopqrstuvwxyz_*";
string special = TextBox2.Text;
I assume you want to check the existence of substring and remove from the parent string, Try this
string alphabet = "abcdefghijklmnopqrstuvwxyz_*";
string special = textBox2.Text;
if (alphabet.ToLowerInvariant().Contains(special))
{
textBox3.Text = alphabet.Replace(special, "");
}