I’m working on formatting C# code in HTML. I’m trying to replace tabs/indents with 4 spaces.
Here’s an example.
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Hello World");
}
I need to replace the tab before Response.Write with 4 spaces.
I tried things like ^\t, with different variations, tried ^\s\s\s\s. I thought this would be simple, but nothing I’ve tried seemed match the tabs.
What am I doing wrong?
Thank you!
Edit
I copy directly from VS into TextBox1.

As you can see, there are no actual tabs (\t) in the TextBox value, which is the root of the problem. As noted in my comments, the spaces with ^ did work (for the first line only).
So my final regex will look like… this: “\s\s\s\s”.
This should do what you want:
See it online: ideone
Update
Here’s a version for ASP.NET Web Forms that runs in Visual Web Developer 2010 Express:
Default.aspx
Default.aspx.cs
Result after clicking button:
protected void Page_Load(object sender, EventArgs e) { ****Response.Write("Hello World"); }The asterisks are there only to make it easy to see that the tabs have been replaced correctly with spaces. Change the
'*'to' 'to get spaces instead of asterisks.