You are on page 1of 4

remove first three character from string

String oldString = ""+919824335667";

string newNumber = oldString .Remove(0, 3);

remove first 10 characters from a string


str = "hello world!";
str.Substring(10, str.Length-10)

Or
string s = "hello world";
s=s.Substring(10, s.Length-10);
Or
string s = "hello world!";
s = s.Substring(Math.Max(0, Math.Min(10, s.Length - 1)));

Remove last comma in a string c# WinForms


string s = "1,5,12,34,12345";
int index = s.LastIndexOf(',');
Console.WriteLine(s.Remove(index, 1));
Output will be;

1,5,12,3412345

Or
string str = "1,5,12,34,";
string removecomma = str.Remove(str.Length-1);
MessageBox.Show(removecomma);

Or
1. string s = "test";
2. s = s.Remove(s.length - 1);
3. Output : "tes"
Removing First and Last Character from String In
C# protected void Page_Load(object sender, EventArgs e)

remove_sym();

public void remove_sym()

string str = "sd,ff,gg,hh,jj,kk,";

string str2 = ",sd,ff,gg,hh,jj,kk,";

string str3 = ",sd,ff,gg,hh,jj,kk,";

Response.Write("Actual string Is : " + str);

Response.Write("<br/>");

Response.Write("Removing Last Chracter : "+str.Remove(str.LastIndexOf(","), 1));

Response.Write("<br/>");

Response.Write("<br/>");

Response.Write("<br/>");

Response.Write("Actual string Is : " + str2);

Response.Write("<br/>");

Response.Write("Removing First Chracter : "+str2.Remove(str2.IndexOf(","), 1));

Response.Write("<br/>");

Response.Write("<br/>");

Response.Write("<br/>");

Response.Write("Actual string Is : " + str3);


Response.Write("<br/>");

str3 = str3.Remove(str3.IndexOf(","), 1);

Response.Write("Removing First and Last Chracter :


"+str3.Remove(str3.LastIndexOf(","), 1));

Output will be :-

Remove Last Character from String in C#

string mystring= "1,2,3,4,5,6,7,8,9,10,";


string output= mystring.Remove(mystring.Length - 1, 1);
Response.Write(output);

You might also like