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, "");
}
Related
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 8 years ago.
Improve this question
I have a large text. I need find any word in the text then copy to variable the phrase that contains the word. How can I do this by C#? Maybe I can use some regular expression?
Use the regex expression [^.!?;]*(search)[^.?!;]*[.?!;], where "search" is your query.
string query = "professional";
var regex = new Regex(string.Format("[^.!?;]*({0})[^.?!;]*[.?!;]", query));
string text =
#"Stack Overflow is a question and answer site for professional and enthusiast programmers.
It's built and run by you as part of the Stack Exchange network of Q&A sites.
With your help, we're working together to build a library of detailed answers to
every question about programming.";
var results = regex.Matches(text);
for (int i = 0; i < results.Count; i++)
Console.WriteLine(results[i].Value.Trim());
This code uses the regex to find all sentences containing "professional", and outputs them, trimming any whitespace.
Output: Stack Overflow is a question and answer site for professional and enthusiast programmers.
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,"."));
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want regx pattern in C# which find substring in any string which comes in middle only. Let say ,
Input : "toprohitpop rohittoppop toppoprohit"
find substring : "rohit"
Replace with : "$$$$"
Output : "top$$$$pop rohittoppop toppoprohit"
if substring "rohit" comes in left or right of the string then it should not be replaced.Substring "rohit" will only be replaced when it comes in middle of string .
Thanks in advance.
Use non-word-break anchors:
\Brohit\B
The \B will only match if it is in the middle of a word.
Read about it.
var input = "toprohitpop rohittoppop toppoprohit";
var regex = new Regex(#"\Brohit\B");
var output = regex.Replace(input, "$$$$$$$$");
See "Anchors" in Regular Expression Language.
Also, be careful with the '$' in the substitution string (see comments)
Use the following regex: .+rohit.+
Basically it enforeces at least one char before rohit and one after
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to trim a string and remove all the words that occur after a certain word.
For example - If the string contains 'very' text
string mySentence=" Today is very nice day! ";
if (mysentence.Contains(very))
{
//remove everything that starts with 'very' until rest of the line..
}
result should be:
Today is
First you split using the required word
string[] splits = mysentence.Split("very");
Since you've already made certain that "very" is inside the string, this will get you two strings. You want the first one (the split before the "very"). You need to trim the extra space from that one so:
string result = splits[0].Trim();
Try this
string mySentence = " Today is very nice day! ";
if (mySentence.Contains("very"))
{
mySentence = mySentence.Remove(mySentence.IndexOf("very")).Trim();
}