c#-3.0

Using a string builder, i've read a file.. How do i find if the given string is present in the file or not?

别说谁变了你拦得住时间么 提交于 2021-02-18 08:31:28
问题 I've read a file into StringBuilder. When I give a string as an input, if the word is present in the file, the output should be true.. If its not present, it should be false.. How do i do it? Could someone help me with the code? I've written the program till here.. How do i go further? Thanks alot.. :) class Program { static void Main(string[] args) { using (StreamReader Reader = new StreamReader("C://myfile2.txt")) { StringBuilder Sb = new StringBuilder(); Sb.Append(Reader.ReadToEnd()); {

C# What query language to specify in rule to pull out the two book nodes

女生的网名这么多〃 提交于 2021-02-11 15:12:30
问题 <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per Bothner</author> <author>Kurt Cagle<

C# What query language to specify in rule to pull out the two book nodes

最后都变了- 提交于 2021-02-11 15:12:19
问题 <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per Bothner</author> <author>Kurt Cagle<

How to stop function once message box displayed

雨燕双飞 提交于 2021-02-10 23:19:42
问题 public void CreateFileOutput(object parameter) { TransactFileCreation(); WPFMessageBox.Show("test", "Process completed successfully."); } public void TransactFileCreation() { if (BatchFolderPath == null) { WPFMessageBox.Show("test", "Select a Batch folder"); return; } // code.. } I am calling TransactFileCreation() from CreateFileOutput(). Once Msg Box displayed, further the function should not work. But in my case, it again go to the main function and displaying msg box present in that. How

How to stop function once message box displayed

对着背影说爱祢 提交于 2021-02-10 23:18:01
问题 public void CreateFileOutput(object parameter) { TransactFileCreation(); WPFMessageBox.Show("test", "Process completed successfully."); } public void TransactFileCreation() { if (BatchFolderPath == null) { WPFMessageBox.Show("test", "Select a Batch folder"); return; } // code.. } I am calling TransactFileCreation() from CreateFileOutput(). Once Msg Box displayed, further the function should not work. But in my case, it again go to the main function and displaying msg box present in that. How

How to draw a rectangle in C# using a mouse

陌路散爱 提交于 2021-02-10 18:00:42
问题 I want to draw a rectangle on a form in C#. I read and found this article. Are there any samples or tutorials available ? The article was not very helpful. 回答1: The article you linked appears to be C++, which may explain why it didn't help you much. If you create events for MouseDown and MouseUp, you should have the two corner points you need for a rectangle. From there, it's a matter of drawing on the form. System.Drawing.* should probably be your first stop. There are a couple of tutorials

Count the characters individually in a string using c#

亡梦爱人 提交于 2021-02-08 12:17:27
问题 I have a string as follows: string str = "ssmmmjjkkkkrrr" Using C#, I need to display the count of each individual character as follows: s = 2 m = 3 j = 2 k = 4 r = 3 Thanks in advance. 回答1: The simplest way would be to use LINQ: var counted = text.GroupBy(c => c) .Select(g => new { g.Key, Count = g.Count() }); foreach (var result in counted) { Console.WriteLine("{0} = {1}", result.Key, result.Count); } Or even more briefly: foreach (var group in text.GroupBy(c => c)) { Console.WriteLine("{0}

Count the characters individually in a string using c#

落爺英雄遲暮 提交于 2021-02-08 12:15:44
问题 I have a string as follows: string str = "ssmmmjjkkkkrrr" Using C#, I need to display the count of each individual character as follows: s = 2 m = 3 j = 2 k = 4 r = 3 Thanks in advance. 回答1: The simplest way would be to use LINQ: var counted = text.GroupBy(c => c) .Select(g => new { g.Key, Count = g.Count() }); foreach (var result in counted) { Console.WriteLine("{0} = {1}", result.Key, result.Count); } Or even more briefly: foreach (var group in text.GroupBy(c => c)) { Console.WriteLine("{0}

how to go from TreeNode.FullPath data and get the actual treenode?

余生颓废 提交于 2021-02-07 19:36:38
问题 I would like to store some data from TreeNode.FullPath and then later i would like to re-expand everything up to that point. Is there a simple way of doing it? Thanks a lot! 回答1: I had a similar problem (but I just wanted to find the treenode again) and found this: http://c-sharpe.blogspot.com/2010/01/get-treenode-from-full-path.html i know it only answers part of your problem, but better than no replies at all ;) 回答2: You can write it as an extension method to the TreeNodeCollection : using

Custom Linq Ordering

蓝咒 提交于 2021-02-06 11:11:50
问题 I have over a thousand folders, each folder contains one or more files with the following names: Unordered: Alison.ext Heather.ext Molly.ext Paula.ext Sam.ext Ordered: Molly.ext Sam.ext Heather.ext Alison.ext Paula.ext I would like to write an expression to sort this list as described above. 回答1: //Creating a dictionary with the custom order var order = "MSHAP"; var orderDict = order.Select((c,i)=>new {Letter=c, Order=i}) .ToDictionary(o => o.Letter, o => o.Order); var list = new List<string>