Remove similar characters from list [closed] - c#

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am making a app to generate a password
Now I have a character list which use the following characters when all options for generate a password are null:
chars = "$%##!*abcdefghijklmnopqrstuvwxyz1234567890?;:ABCDEFGHIJKLMNOPQRSTUVWXYZ^&".ToCharArray();
Next I have a else with some options like Punctuation and Symbols, so then he is not using the standard characters:
var listOfCharacters = string.Empty;
foreach (var currentOption in options)
{
switch (currentOption)
{
case GenOptions.Punctuation:
listOfCharacters += "&#.#%!*?;:,";
break;
case GenOptions.Symbols:
listOfCharacters += "^$";
break;
default:
break;
}
}
chars = listOfCharacters.ToCharArray();
listOfCharacters.Remove('i'); listOfCharacters.Remove('!');
listOfCharacters.Remove('l'); listOfCharacters.Remove('1');
listOfCharacters.Remove('O'); listOfCharacters.Remove('o');
listOfCharacters.Remove('0'); listOfCharacters.Remove('q');
listOfCharacters.Remove('p'); listOfCharacters.Remove('g');
listOfCharacters.Remove('I');
Now I want to build in a option to remove Similar characters so characters who are almost a copy from each other like o and 0. I have want to do this with listofcharacter.remove but when I use it like above it gives me a error because its null/empty. Now how can I fix this?

Not sure about null/empty error messages.
You are trying to use String.Remove, which takes character index as an argument. So, when you pass 'i' it is first converted to int and then String.Remove tries to delete character with that index. As far as I understand it's not what you want it to do.
You can use String.Replace instead:
String.Replace('!',String.Empty);

Try this:
listOfCharacters.Replace('i',' ');

Related

How to write the regex expression? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
The input string: A+SUM(A)C+AB-C+SUM(A)+1
I want to replace A with 0, the result like this:0+SUM(A)C+AB-C+SUM(A)+1
or replace SUM(A) with 0, the result like this:A+SUM(A)C+AB-C+0+1
Thanks
Without Regex (because Regex is overkill for this):
var s = "A+SUM(A)+B-C";
var replaceBeginningA = s.Replace("A+", "0+");
var replaceSumA = s.Replace("SUM(A)", "0");
Console.WriteLine(replaceBeginningA); // 0+SUM(A)+B-C
Console.WriteLine(replaceSumA); // A+0+B-C
As pointed out in the comments though, you need to provide more detail if this input is expected to have a different format.
maybe:
replace ^A with 0
replace SUM\(A\) with 0
Try thus:
string replaced = Regex.Replace(input, #"\b(\w+)\+SUM\(\1\)", "0+0");
This will match anything of the form
foo+SUM(foo)
and replace it with 0+0

Replacing between chracters by unicode identifier [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How to replace between two characters in a string based on their Unicode code point ?? Could any help please ??Many Thanks.
For example,
Replace (U0041 with U0066)
Use the \u escape code to write the characters:
str = str.Replace('\u0041', '\u0066');
Alternatively, convert the numbers into characters:
int char1 = 65;
int char2 = 102;
str = str.Replace((char)char1, (char)char2);
You can do it like this:
Console.WriteLine("ABC".Replace("\u0041", "\u0066"));
This produces the output fBC, because the unicode code point of u0041 (which is A) has been replaced with the code point of u0066 - an f.

Search in a text file from one symbol to another [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am coding program, and stacked. Please can give me a code which search text in file from one specific symbol to another using C# visual Windows Forms , not console application. Like this text in textfile c:\id.txt
The entry was successfully copied to {ea4c4653-cc65-11e1-a2fc-001e101f4e71}.
search string from { to } , and result with { and }, without . at the end. And send found text in a message box.Code to search text in a file an send whole line in message box. But i need part of line.
Regex can be useful:
MessageBox.Show(
Regex.Match(inputString, "\{(?<path>[^}]*)\}").Groups["path"].Value);
explain:
{ '{'
[^}]* any character except: '}'
(0 or more times, matching the most amount possible)
} '}'
Try by using regular expressions:
var line = " The entry was successfully copied to {ea4c4653-cc65-11e1-a2fc-001e101f4e71}.";
var foo = Regex.Match(line, #"to\s*\{([^}]+)\}");
if(foo.Success) {
MessageBox.Show(foo.Groups[1].Value); //ea4c4653-cc65-11e1-a2fc-001e101f4e71
} else {
//not found value
}

c# string confusion [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am fairly new to C# and am confused about something.....
Let me show you whats happening and hopefully you guys can tell me what im doing wrong here.
string incomming = Encoding.UTF8.GetString(bytes);
//MessageBox.Show(incomming); shows me the string "stop", No problem
executeCommand(incomming);
public void executeCommand(string action)
{
MessageBox.Show(action + " was recieved"); // shows the string "stop", No problem here... that works
switch (action)
{
case "start":
MessageBox.Show("start was recieved"); //shows nothing
break;
case "stop":
MessageBox.Show("stop was recieved"); //shows nothing
break;
}
}
With out knowing what the contents of the Byte array that is being converted to a String it is very hard to give you anything help you. But here are a few things to try.
You can put a breakpoint on executeCommand(incomming) and in your watch window type incomming.ToCharArray(), you will need to click on the green circle in the value column before you can see the characters that are apart of the string. This should let you know what you are dealing with.
You can search incomming for a match of the string you are looking for by using the String.Contains Method.
if (action.Contains("stop"))
MessageBox.Show("stop was recieved");
else if (action.Contains("start"))
MessageBox.Show("start was recieved");
The only reasonable explanation for this is that one of your "stop" strings has a letter in a diferent language from english but looks the same. In this case:
"stop" != "stоp"
is true;

How do I remove a portion of my string? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Continuing from my previous question, I now want to remove the number once I have found it and stored it in a variable.
Just a slight tweak to my response to your first question to instead use Regex.Replace method will git 'er done.
Don't worry I figured it out. Just need to find the length then delete the chars
(qual is the intergers found)
string length = qual.ToString();
int length2 = length.Length;
text.Remove(0, length2);
I think the following code resolves the root problem:
string originalString = "35|http://www.google.com|123";
string[] elements = originalString.Split(new char[] { '|' }, 2);
int theNumber = int.Parse(elements[0]); // 35
string theUrl = elements[1]; // http://www.google.com|123

Categories