|
you may want to look at this thread[^]. Without any guarantee!
|
|
|
|
|
I've been trying to figure this out for over an hour and haven't had any luck. While doing a string comparison, this works but is case sensitive ... I'd like to make it case insensitive, any ideas on how to do this?
while ((line = file.ReadLine()) != null)
{
if (line.Contains(searchString))
{
textBox12.Text += "Line Number " + counter.ToString() + ":" + "\r\n";
textBox12.Text += line + "\r\n";
textBox12.Text += "\r\n";
}
counter++;
}
Complete function
if (checkBox1.Checked == false)
{
foreach (string i in xmlFileNames)
{
FileStream fs = new FileStream(@i, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
StreamReader xmlStream = new StreamReader(@i);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(fs);
string allRead = xmlStream.ReadToEnd();
string line = null;
int counter = 0;
string testString = Regex.Match(allRead, searchString, RegexOptions.IgnoreCase).ToString();
if(Regex.Match(allRead, searchString, RegexOptions.IgnoreCase).Success == true)
{
System.IO.StreamReader file = new System.IO.StreamReader(@i);
while ((line = file.ReadLine()) != null)
{
if (line.Contains(searchString))
{
textBox12.Text += "Line Number " + counter.ToString() + ":" + "\r\n";
textBox12.Text += line + "\r\n";
textBox12.Text += "\r\n";
}
counter++;
}
}
xmlStream.Close();
}
textBox12.AppendText("Number of xmls listed: " + xmlFileNames.Count().ToString());
}
|
|
|
|
|
Unfortunately, the Contains method does not support any of the StringComparison overloads that othr methods do.
The workaround is to use IndexOf which does:
if(line.IndexOf(searchString, StringComparison.OrdinalIgnoreCase) >= 0)
{
...
}
|
|
|
|
|
That worked well, thank you
|
|
|
|
|
|
Bad idea when working with non-Latin General char sets.
|
|
|
|
|
I know, but most people would have used it and moved on. And maybe sought/asked for a better solution later.
|
|
|
|
|
First define an IEqualityComparer like this:
class CharEqualityComparer : IEqualityComparer<Char>
{
bool ignoreCase;
pubilc CharEqualityComparer(bool ignoreCase)
{
this.ignoreCase = ignoreCase;
}
pubilc CharEqualityComparer() : this(false);
{
}
public bool Equals(Char c1, Char c2)
{
c1 = (ignoreCase) ? c1.ToString().ToLower().ToCharArray()[0] : c1;
c2 = (ignoreCase) ? c2.ToString().ToLower().ToCharArray()[0] : c2;
if (c1 == c2)
{
return true;
}
else
{
return false;
}
}
public int GetHashCode(Char c)
{
int hCode = (int)c;
return hCode.GetHashCode();
}
}
and then do this in your code
if (line.Contains(searchString, new CharEqualityComparer(true)))
Hope this helps!
Cheers
Manfred
|
|
|
|
|
That looks correct but expensive, as each pair of characters may result in the creation of several string objects.
The community content on MSDN[^] suggests another approach.
|
|
|
|
|
Just to enhance upon this solution, instead of doing a ToUpper/ToLower, you can use String.Equals with a StringComparison overload:
public bool Equals(Char c1, Char c2)
{
var comparison = (ignoreCase) ? StringComparison.OridinalIgnoreCase : ? StringComparison.Oridinal;
return String.Equals(c1.ToString(),c2.ToString(),comparison);
}
|
|
|
|
|
Thanks for that info!
Cheers
Manfred
|
|
|
|
|
Write an extension method that overloads the string.Contains() method.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi
I need to play(render) a video stream from an IP camera. Since media element does not support rtsp protocol, I created a rtsp client which connects to the camera. Now I am not sure what to do with that stream? My best guess is to save it file, and than use media player to render it. Does anybody knows how to do that? What I am concerned is, when to delete old data from the file and how can the same file be opened for reading and writing at the same time? If anybody has any ideas how to solve those problems, please let me know.
Uroš
|
|
|
|
|
|
That app. just downloads a jpeg and renders it - in my case I access a 3GP encoded file.
|
|
|
|
|
Hi
In my c# windows application I have a registration form having dropdown of Country, State and City fields.
I want to fill these dropdown from web as I don't want to fill them from database or any hard coded values. Is there any web service which provide the Country, State and City related updates or Is there any other way to Implement this?
Please Help..
Thanks in advance
|
|
|
|
|
|
I also found this link but here I didn't found the way to get City an states corresponding to that country.
I know I can also get list of all country using culture info in c#. But still unable to get list of state or city.
|
|
|
|
|
Don't; they'd be too long. Simply allow the user to type the input and then validate it. Drp down and such are for when you have a very few, lengthy, entries.
|
|
|
|
|
hi all,
i develop a windows application in c#, and i want to add an own button in controlbox (close,minimize,maximize) buttons, and override the window menu (right click on window bar show a menu contain the controlbox buttons as menu).
can i create an own button and override the menu for the window using c#, and how to do that??
thanks all.
|
|
|
|
|
It depends on what your target OS is. A solution that works on XP may not necessarily work in Vista/Win 7, but there's a question with some answers here[^] that might just help.
|
|
|
|
|
All,
I have a console application that's not mine; it cannot be modified. After starting it with a bunch of command line parameters, it computes something and displays the result on it's console. I would like to get the PARTIAL output and then kill it.
I have found several code examples that seemed promising. My problem is that I can't seem to read any output before the program is finished and I need partial output to decide to kill it, since it will compute much more that I don't need after the initial computations.
Jan C. de Graaf
|
|
|
|
|
I am assumming you are talking about a console program that runs from a command window?
If so the open a second command window. In the first command window,start the program and pipe output to a text file, and in the other command window do a type command on the text file with a more option pipe. As the file fills up you can scan it at your own reading pace.
|
|
|
|
|
Thank for your quick response!
I can run the console program from a command window yes.
>> with a more option pipe
What is a "more option pipe" ? Is this like 'tail' in most unixes? Can you give an example please.
I was hoping to use C# and the Process class and the RedirectStandardOutput option. But ran into the problem I described in my original question.
Jan.
|
|
|
|
|
when done correctly, one can get data from both the output and the error stream of a running app.
using Stream.ReadToEnd() would not be part of the correct way; using an extra thread would.
So maybe you should show a relevant snippet of your code for people to comment on.
|
|
|
|