This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int CountChar(string src, char x) | |
{ | |
int count = 0; | |
for (int i = 0; i < src.Length; i++) | |
{ | |
//.ToString().ToUpper(): CaSe sensitive or not | |
if (x.ToString().ToUpper() == src[i].ToString().ToUpper()) count++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private string CapitalizedString(string input) | |
{ | |
string[] arr = input.Split(' '); | |
string result = string.Empty; | |
foreach (string a in arr) | |
{ | |
result += a.First().ToString().ToUpper() + a.Substring(1) + " "; | |
} | |
return result.Trim(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string str = "Hello World1"; | |
str = str.Remove(str.Length - 1); | |
//str is now "Hello World" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string[] arr = ... | |
List<string> list = new List<string>(arr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<string> names = new List<string>() { "John", "Anna", "Monica" }; | |
var result = String.Join(", ", names.ToArray()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<T> noDupes = noDupes.Distinct().ToList(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static string ReplaceEx(string original, string pattern, string replacement) | |
{ | |
int count, position0, position1; | |
count = position0 = position1 = 0; | |
string upperString = original.ToUpper(); | |
string upperPattern = pattern.ToUpper(); | |
int inc = (original.Length / pattern.Length) * | |
(replacement.Length - pattern.Length); | |
char[] chars = new char[original.Length + Math.Max(0, inc)]; | |
while ((position1 = upperString.IndexOf(upperPattern, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example #1 | |
// Read the file as one string. | |
string text = System.IO.File.ReadAllText(@"C:\Users\Public\TestFolder\WriteText.txt"); | |
// Example #2 | |
// Read each line of the file into a string array. Each element | |
// of the array is one line of the file. | |
string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Public\TestFolder\WriteLines2.txt"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compose a string that consists of three lines. | |
string lines = "First line.\r\nSecond line.\r\nThird line."; | |
// Write the string to a file. | |
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt"); | |
file.WriteLine(lines); | |
file.Close(); | |
//In order to append an existing file, set the Boolean parameter to true, as follows: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private string HtmlSrc(string url) | |
{ | |
try | |
{ | |
HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create(url); | |
myWebRequest.Timeout = 5000; // Set time out | |
myWebRequest.ReadWriteTimeout = 6000; // Set Read Write time out | |
myWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1);Accept-Language:vi"; | |
WebResponse myWebResponse = myWebRequest.GetResponse(); | |
Stream ReceiveStream = myWebResponse.GetResponseStream(); |
OlderNewer