using System; class MainClass { public static void Main() { string[] myStrings = {"To", "be", "or", "not","to", "be"}; string myString9 = String.Join(".", myStrings); Console.WriteLine("myString9 = " + myString9); } }
ASP.NET & Csharp (C#)
ASP.NET & Csharp (C#) , Here you can find my posts about .NET c# .
use the Copy() method to copy a string
using System; class MainClass { public static void Main() { string myString4 = String.Concat("Friends, ", "Romans"); Console.WriteLine("myString4 = " + myString4); Console.WriteLine("Copying myString4 to myString7 using Copy()"); string myString7 = String.Copy(myString4); Console.WriteLine("myString7 = " + myString7); } }
use the addition operator (+) to concatenate strings
using System; class MainClass { public static void Main() { string myString6 = "To be, " + "or not to be"; Console.WriteLine(""To be, " + "or not to be" = " + myString6); } }
use the Concat() method to concatenate strings
create some strings
using System; class MainClass { public static void Main() { string myString = "To be or not to be"; string myString2 = "... that is the question"; string myString3 = @" Friends, Romans, countrymen, lend me your ears"; // display the strings and their Length properties Console.WriteLine("myString = " + myString); Console.WriteLine("myString.Length = " + myString.Length); Console.WriteLine("myString2 = " + myString2); Console.WriteLine ("myString2.Length = " + myString2.Length); Console.WriteLine("myString3 = " + myString3); Console.WriteLine ("myString3.Length = " + myString3.Length); } }
Is Palindrome
using System;
using System.Text;
public class MainClass {
public static bool IsPalindrome(string s) {
int iLength, iHalfLen;
iLength = s.Length – 1;
iHalfLen = iLength / 2;
for (int i = 0; i <= iHalfLen; i++) {
if (s.Substring(i, 1) !=
s.Substring(iLength - i, 1)) {
return false;
}
}
return true;
}
static void Main(string[] args) {
string[] sa = new string[]{"level", "minim", "radar"};
foreach (string v in sa)
Console.WriteLine("{0} {1}",v, IsPalindrome(v));
}
}
[/csharp]
Use HttpUtility.HtmlEncode to encode the input string
using System; using System.Web; using System.IO; class MyNewClass { public static void Main() { String myString; Console.WriteLine("Enter a string having '&' or '"' in it: "); myString=Console.ReadLine(); String myEncodedString; // Encode the string. myEncodedString = HttpUtility.HtmlEncode(myString); Console.WriteLine("HTML Encoded string is "+myEncodedString); StringWriter myWriter = new StringWriter(); // Decode the encoded string. HttpUtility.HtmlDecode(myEncodedString, myWriter); Console.Write("Decoded string of the above encoded string is "+myWriter.ToString()); } }