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
}
Related
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.
Function receives char[,].
For example if it it takes
000
LAD
0B0
Traversing should print out all possible combinations of non-zero chars:
L
LA
LAD
LAB
A
AL
AB
AD
and so on
private void Traverse(char[,] area)
{
}
The easiest way is to write a recursive function with two strings, initial and output. I assume you want combinations, not permutation so it's a little easier. The base case is checking if initial is empty, then print out the output. The step is removing a character from initial and calling the recursive function twice, one with the unchanged output and one with the removed character added into the output. If the removed character is 0, however, then you only call the function once (removing the 0 without adding anything to the output.)
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',' ');
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;
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 have an array of words and I want to remove them from an input string, could anyone tell me what is the better way to conduct this task?
This should work
string[] arrToCheck = new string[] { "try ", "yourself", "before " };
string input = "Did you try this yourself before asking";
foreach (string word in arrToCheck )
{
input = input.Replace(word, "");
}
MessageBox.Show("result is "+input);
input variable will now have a string which does not have those words in your array.
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 11 years ago.
I have an file text with approximate 113687 lines, but my application reads only 314 lines, can anyone say why?
My code:
string file = #"z:\foo.txt";
StreamReader reader = File.OpenText(file);
string line;
int rows = 0;
while ((line = reader.ReadLine()) != null) {
++rows;
doSomethingWith(line);
// ...
}
The DoSomethingWith function is similar to:
protected static bool DoSomethingWith(string line)
{
return Regex.Match(line, #"\d+\-\d+\.\d+\.\d+\.\d+").Success;
}
Updated:
In answer to Gregs question:
Does your foo.txt contain a Ctrl+Z character on line 314?
Yes, my file contains a Control-Z character on line 314.
Text files on Windows can be terminated with a Ctrl+Z character. This means that when the file is read, the StreamReader returns end-of-file when the Ctrl+Z is encountered. Any data following the Ctrl+Z is not read.
If you wish to read the entire file without this text-mode behaviour, use File.OpenRead instead of File.OpenText.