Login


Text Handling

Articles related to working with strings and text.
General Programming » Text Handling

 

General
Miscellaneous topics related to string manipulation.

A Case-Insensitive Version of String.Replace()
The String.Replace() method is useful for easily replacing all occurrences of a substring with another substring. However, this method is always case-sensitive. Here is an extension method that implements a case-insensitive version of String.Replace().
By Jonathan Wood on Wednesday, September 26, 2012

A JavaScript Formatter
JavaScript that has been compressed to use less bandwidth can be very difficult to read. Here's a C# class that will format JavaScript code, making it easy to read again.
By Jonathan Wood on Tuesday, April 08, 2014

A SQL QueryBuilder Class
Use the QueryBuilder class to programmatically create SQL queries. This article also discusses the pros and cons of such an approach.
By Jonathan Wood on Friday, January 28, 2011

Converting Between Integers and Spreadsheet Column Labels
Instead of numbers, spreadsheet programs use a system of letters to label columns. Here's a handy routine that can convert an integer value to a column label, and also convert column labels back to integers.
By Jonathan Wood on Monday, April 11, 2011

Converting Between Integers and Strings Using Any Base
.NET provides the Convert class, which among other things can convert between integers and strings using different bases. Inexplicably, the Convert class only supports base 2, 8, 10 and 16. Here's a class that can convert between integers and strings using any base.
By Jonathan Wood on Monday, April 11, 2011

Converting Numbers to Ordinal Strings
Here's a simple routine that converts a number (1, 2, 3, etc.) to an ordinal string (1st, 2nd, 3rd, etc.)
By Jonathan Wood on Saturday, February 26, 2011

Converting Numbers to Words
This article presents some code that converts a number into words. For example, it converts 12345 to "Twelve thousand, three hundred forty-five and 00/100." This code is ideal for a check-writing program but easily could be adapted to other uses.
By Jonathan Wood on Wednesday, December 29, 2010

Generating and Parsing Roman Numerals
Here's a handy class that contains methods for converting integers to Roman numerals, and Roman numerals back to integers.
By Jonathan Wood on Monday, April 11, 2011

Implementing Word Wrap in Email Messages
In this article, the author presents code to implement word wrap in emails sent using C# on the .NET platform.
By Jonathan Wood on Wednesday, July 04, 2012

HTML & URLs
Articles about working with strings that are related to HTML or URLs.

Abbreviating URLs
Abbreviating a URL is easy: Just truncate it. However, this article shows how you can more intelligently truncate a URL so that it conveys more information about the full URL.
By Jonathan Wood on Sunday, December 12, 2010

Colorizing Source Code
Here's some C# code you can use to colorize source code (syntax highlighter) you plan to display on a web page. This code can be used to colorize source code for any programming language that you can write the rules for.
By Jonathan Wood on Wednesday, October 30, 2013

Convert HTML to Text
I recently wrote about converting plain text to HTML. Here's some code to convert HTML back to plain text. This code should come in handy for any situation where you need to extract plain text from the Web.
By Jonathan Wood on Tuesday, April 05, 2011

Converting Text to a URL-Friendly Slug
It is common practice these days to include a URL-friendly version of your title, often called a slug, within your URLs. Here's a simple routine to generate one.
By Jonathan Wood on Sunday, December 12, 2010

Converting Text to HTML
Here's a simple routine that will format a string as HTML so that it can be displayed on a web page. It extends the functionality offered by the HttpUtility.HtmlEncode() method.
By Jonathan Wood on Thursday, March 31, 2011

Resolving Partial URLs
This article presents code that resolves a partial URL by combining it with a base URL.
By Jonathan Wood on Thursday, December 16, 2010

Parsing
Articles related to parsing strings.

A C# Command-Line Parser
.NET applications can use Environment.CommandLine to access any command-line arguments that were supplied to the program. However, there's more work to do if your command line support many options. Here's a command-line parser class to make it easy.
By Jonathan Wood on Tuesday, March 22, 2011

A Simple CSS Parser
I recently encountered a question on stackoverflow about parsing CSS. Although I've written a bunch of parsing routines, I'd never thought to parse CSS. I've never had a reason to do so. Still, I had a bit of time and thought it might be interesting to put something together.
By Jonathan Wood on Thursday, August 22, 2013

A sscanf() Replacement for .NET
C and C++ developers have used the sscanf() function for many years as a quick and easy way to parse well-structured input. Here's a class that brings the same functionality to .NET.
By Jonathan Wood on Friday, February 25, 2011

A Text Parsing Helper Class
If you need to write code that parses text, this helper class can make things easier for you.
By Jonathan Wood on Thursday, December 23, 2010

Parsing HTML Tags in C#
Here's some code that will parse the tags in an HTML page. Perfect for tasks like finding all the out-going links on a page.
By Jonathan Wood on Friday, December 31, 2010

Parsing Text with Extension Methods
Extension methods are a cool new feature of C#. This article describes extension methods and presents code that adds a number of methods related to text parsing to the String class.
By Jonathan Wood on Monday, March 07, 2011

Quick and Easy Method to Remove Html Tags
Here's a short snippet of code you can use to strip out HTML tags from a block of text.
By Jonathan Wood on Sunday, April 08, 2012

Splitting a Name into First and Last Names
Although splitting a name into the first and last names is not a major task, it's not quite as trivial as you might first expect due to potential variations.
By Jonathan Wood on Sunday, January 30, 2011