Source Code Syntax Highlighting
Developers like to set different amounts of spaces for their tab settings. Sometimes we just use the default tab settings of our favorite IDE. Sometimes we're stuck with a particularly non-friendly IDE for a specific project, which doesn't allow adjusting the tab spacing. In these circumstances, it is helpful to convert tabs to spaces for blogging.
public static string TabToSpaces(string inStr, int numSpaces) {
StringBuilder buf = null;
char[] chars = null;
char curr_char;
string str = "some characters";
int i = 0;
if (inStr == null)
{
return null;
}
chars = inStr.ToCharArray();
buf = new StringBuilder();
while (i < inStr.Length)
{
curr_char = chars[i];
if (curr_char == '\t')
{
for (int z = 0; z < numSpaces; z++)
{
buf.Append(' ');
}
}
else
{
buf.Append(curr_char);
}
i++;
}
return buf.ToString();
}
some inline cpp System::Console::WriteLine("halo!"); test inline cpp
more c#
public void Main(string[] args)
{
// comments
}
some inline c# highlighter = HighlighterFactory.GetHighlighter("C#", "C#"); gets a c# highlighter
#pragma once
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
In most situations outside of <pre> tags, browsers ignore spacing
beyond a single white space. When you want to display a non-breaking
space, sometimes it can be helpful to convert spaces to their
non-breaking browser counterparts.
more inline c# #region public static string SpaceToNbsp(string inStr) { } convert space to nbsp.
some inline Java highlighting public synchronized String MakeLines(int numLines) {/* comment */ } make some pretty line
numbers
tabular java:
import java.util.HashMap;
/**
* A rudimentary cache.
*/
public class Cache extends HashMap {
public synchronized Object get(Object key) {
return super.get(key);
}
public synchronized Object put(Object key, Object value) {
return super.put(key, value);
}
public synchronized void clear() {
super.clear();
}
}
more inline cpp:
int j = *static_cast<__box int*>(o1); __nogc new o()->optimize();
Testing out the sytax highlighting extension.