views:

110

answers:

6

Is there an equivalent of PHP's highlight_string function in C#?

It is not necessary to be a built-in function.

Edit: If not is there a good library for that?

Edit2: I really need a server side solution for that like PHP does.

+1  A: 

Nope, certainly not in the Framework itself. You'd have to look for libraries that support this.

Quibblesome
@Quibblesome I googled but did not find a good solution.
JCasso
A: 

There's a list of syntax highlight plugins in javascript that you could use.

Darin Dimitrov
@Darin Dimitrov: I am searching for a server side solution.
JCasso
+1  A: 

If you want it for webpages (which I assume, since the PHP highlight function formats it as HTML) you can use Googles Code prettify. It's however a javascript, which on the other hand makes it code-behind language independent.

I'm using it at my site with great success :-)

You can find it here: http://code.google.com/p/google-code-prettify/

Steffen
+2  A: 

There is nothing in the framework that will give you the coloured output. You will have to use a library to do this.

C# Code Format was one of the first .Net ones to come up in Google, although it only supports highlighting of C#, VB, HTML, XML, T-SQL or Monad. It is capable of running server side though as it is written in C#. If you need it to format PHP, then it is probably quite simple to extend it to do so - just make a custom PHPFormat class.

adrianbanks
I've used C# Code Format as well, however I wasn't quite pleased with it. If I recall correctly it doesn't highlight as much as e.g. Visual Studio (or Google Code Prettify)I don't say this because I'm stubborn, I just thought it might be useful to know.That being said it's probably your best bet, if you want to run it server side.
Steffen
+2  A: 

You can build yourself a basic syntax highlighter easy using RegExp.

Here's an example:

Syntax Highlight in C#

Or if you want a html C# highlighter written in C#

C# Syntax Highlighter 2.0

Or a JS highlighter:

highlight.js

Pop Catalin
@Pop Catalin: I will do it if i cannot find one :) Hope I can find it. I am lazy.
JCasso
+1  A: 

A code formatter in csharp, note the link for sourcecode at the bottom. Hope that helps!

jball