Click here to Skip to main content
12,951,983 members (68,774 online)
Click here to Skip to main content
Add your own
alternative version


46 bookmarked
Posted 18 Sep 2005

String Manipulation Library

, 27 Sep 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
Library of string manipulation functions.


The default .NET string library comes with several functions to manage strings that are quite helpful (Substring, Compare, IndexOf, etc.). The problem is that the amount and variety of these functions is very limited. I find myself constantly needing string handling functions beyond those that are given, and I find myself constantly rewriting the same functions over and over again for new projects. So, I have put together a library of functions that I have found useful. Some are very basic and some are a little more complex, but they are all useful in my opinion.

Using the code

I won't post the actual source code here (it's attached) since there are a lot of functions and it would take up too much of space.

Functions for managing file paths

GetPath(<Full Path>)

The function retrieves the path part from the full filename like, C:\Folder\file.exe -> C:\Folder\.

GetName(<Full Path>)

It retrieves the name of the file from the full filename like, C:\Folder\file.exe - > file, file.exe -> file.

GetExtension(<Full Path>)

It retrieves the extension of the file from a filename C:\Folder\file.exe - > exe, file.exe -> exe.

RemoveExtension(<Full Path>)

It removes the extension from a filename like, C:\Folder\file.exe - > C:\Folder\file, file.exe -> file.

GetFullName(<Full Path>)

It removes the path from a filename like, C:\Folder\file.exe - > file.exe.

Other functions


It checks whether a word or sentence is capitalized like, Word -> True, This is a sentence -> True.


It checks whether a word or character is in lower case like, word -> True, Word -> False.


It checks whether a word or character is in upper case like, word -> False, Word -> False, WORD -> True.


It swaps the cases in a string like, word -> WORD, Word -> wORD, WoRd -> wOrD.


It alternates the cases between letters of a string, the first letter's case stays the same like, Hi -> Hi, longstring -> lOnGsTrInG.


It checks to see if a string has alternate cases like, lOnGsTrInG -> True.


It checks for mixed upper and lower cases like, string -> False, String -> True.

CountTotal(<String>, <Chars>)

It counts total number of a string or character in a string like, hello, l -> 2, hello, he -> 1.


It removes vowels from a string like, remove -> rmv.


It checks to see if a string contains vowels like, hello -> True, rmv -> False.


It checks if a string is nothing but spaces like, " " -> True.


It checks if a string has only numbers like, 12453 -> True, 234d3 -> False.

I know that there is already an existing IsNumeric function, but the existing one takes the input parameter as an Object, so in theory, this function should be faster for larger strings because it takes the input as a String.


It checks if the string contains numbers like, hello -> False, h3llo -> True.


It checks if the string has numbers and letters like, Test1254 -> True, $chool -> False.


It checks if the string contains only letters like, Hi -> True, Hi123 -> False.

Initials(<String>, <Capitalize>, <ReturnSeparator>, <Optional Separator = " ">)

It returns the initials of a name or sentence.

  • Capitalize- To return the initials as lower or upper case.
  • ReturnSeparator - To return the initials with the original separator (John Smith, a space is the separator, so return J. S. or J.S.).
  • Separator - The character that marks the separation of words (John Smith, space is the separator (default)) John Smith -> J. S.
Title(<String>, <Optional Separator = " ">)

It capitalizes the first letter of every word in the string like, the big story -> The Big Story.

IsTitle(<String>, <Optional Separator = " ">)

It checks whether the first letter of each word is capitalized like, The Big Story -> True, The big story -> False.


It checks if a string is in a valid email address-format like, -> True, hahaimfaking -> False. (The function works by assuming the last part is no bigger than 3 letters (com, net, org).)

IndexesOf(<String>, ByVal [Char] As String) As Integer()

It returns all the locations of a given char in a string like, Hello, l -> 2, 3, Hello, o -> 4.

This function works with an ArrayList and then converts it to an Integer array, if you prefer the ArrayList it can be easily modified.

CharRight(<String>, <Position>) As Char

It gets the char in a string at a given position, but from right to left like, string, 0 -> g.

CharMid(<String>, <Position>, <Start>) As Char

It gets the char in a string at a given position from a given starting point, and reads from left to right like, string, 0, 2 -> r.

InsertSeparator(<String>, <Separator As String>)

It inserts a separator after every letter like, hello, "-" -> h-e-l-l-o.

InsertSeparatorEvery(<String>, <Separator>, <Count>)

It inserts a separator after every Count letters like, hello, "-", 2 -> he-ll-o.

InsertSeparatorAt(<String>, <Separator> <Position >)

It inserts a separator at given position like, hello, "-", 3 -> hel-lo.

Substring(<String>, <Start>, <End>)

This is a function that works the same way as the default Substring, but it takes Start and End parameters instead of Start and Length.


It reverses a string like, Hello -> olleH.

PasswordStrength(<String>) As Integer

It is a borrowed function. It returns a rating for how strong the string is as a password. (Max rating is 100).

The credits for the original function goes to D. Rijmenants, this is just a VB.NET version. If there is any problem with copyright or whatever, contact me and I'll delete this. This is just an interesting function that took me a long time to find, so I thought it'd be useful to include it here.

Split(<String>, <Optional Don't Account for Quotes>, <Optional Separator>)

This function is newly added (on 9/27/05). Thanks to j1webb for the idea. This is just like the default Split function, but it keeps everything inside the quotes, intact. For example: 'This is a "very long" string' would return 'This', 'is', 'a', 'very long', 'string'. A limitation of this function is that if there's a quote inside quotes it will mess up. The quote symbol is " by default, but it can be changed to look for ' instead.

Points of interest

Most of these functions are set up to return empty strings or something of that effect when there is an invalid situation, to prevent runtime errors, but feel free to modify them to handle invalid strings in other ways. Some of these functions are dependant on other functions, so make sure to add all the needed functions to your project or merge the needed ones. For functions where a new string was built from the original string, I have used the class StringBuilder since it is much faster when it comes to those bigger strings, if you do not intend to handle large strings then you might want to adjust the function to use a regular String type instead. These functions are not the fastest I'm sure. I wrote them as best as I could, but I'm sure there is room for improvement and optimization.


Some of these functions seem almost pointless, but I have found them to be very useful at some point or the other. Feel free to do whatever you want with these functions, no annoying copyright or anything like that.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
Visit Visual C# Kicks for more .Net Resources and Articles at

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Chintanhiremath21-Mar-12 18:34
memberChintanhiremath21-Mar-12 18:34 
GeneralC# version of these functions Pin
gpmaker12-Apr-08 18:46
membergpmaker12-Apr-08 18:46 
GeneralRe: C# version of these functions Pin
VCKicks16-Dec-08 8:58
memberVCKicks16-Dec-08 8:58 
Questionhow to get numbers from text.. Pin
Eng.hamzeh Abualrob24-Nov-07 23:16
memberEng.hamzeh Abualrob24-Nov-07 23:16 
hey guys,
i would like to know how can i find numbers in text and then save them in other register.?
for examle:
if i have this text : (Laser current is 2.33 mA) and i would like to save just (2.33) in register..
if anyone knows that could you contact me on my e-mail, and i will thank you very much

Eng.Hamzeh abualrob
AnswerRe: how to get numbers from text.. Pin
VCKicks31-Mar-08 18:27
memberVCKicks31-Mar-08 18:27 
AnswerRe: how to get numbers from text.. Pin
Member 90411922-Sep-15 10:31
memberMember 90411922-Sep-15 10:31 
Generalthank you Pin
riquard10-Nov-07 14:28
memberriquard10-Nov-07 14:28 
Generalthnx again.. Pin
BeBadgujar17-Jun-07 18:30
memberBeBadgujar17-Jun-07 18:30 
Questionthank you very much..!!!but..... Pin
BeBadgujar10-Jun-07 18:33
memberBeBadgujar10-Jun-07 18:33 
AnswerRe: thank you very much..!!!but..... Pin
gpmaker10-Jun-07 18:40
membergpmaker10-Jun-07 18:40 
Questionhow to extrat the name of the folder? Pin
BeBadgujar8-Jun-07 22:58
memberBeBadgujar8-Jun-07 22:58 
AnswerRe: how to extrat the name of the folder? Pin
gpmaker10-Jun-07 10:43
membergpmaker10-Jun-07 10:43 
GeneralAnother Needed Function: Name Case Pin
ShutlOrbit26-Apr-07 20:04
memberShutlOrbit26-Apr-07 20:04 
QuestionSuite - or is it Sweet ?? Pin
stixoffire18-Mar-07 4:45
memberstixoffire18-Mar-07 4:45 
GeneralVB6 Shell function Pin
FIFI512-Mar-07 7:56
memberFIFI512-Mar-07 7:56 
GeneralGood job! Pin
Garret1177-Jul-06 3:28
memberGarret1177-Jul-06 3:28 
GeneralGreat Library Pin
ooKmonkey5-May-06 0:49
memberooKmonkey5-May-06 0:49 
Questionany tip for parsing? Pin
kenkenkennek23-Apr-06 0:26
memberkenkenkennek23-Apr-06 0:26 
GeneralGood Work Pin
xoxoxoxoxoxox11-Jan-06 12:29
memberxoxoxoxoxoxox11-Jan-06 12:29 
GeneralCounting... Pin
CoolNetCoder22-Oct-05 4:55
memberCoolNetCoder22-Oct-05 4:55 
GeneralRe: Counting... Pin
gpmaker22-Oct-05 6:32
membergpmaker22-Oct-05 6:32 
GeneralTerrific Library Pin
j1webb27-Sep-05 9:40
memberj1webb27-Sep-05 9:40 
GeneralRe: Terrific Library Pin
gpmaker27-Sep-05 12:03
membergpmaker27-Sep-05 12:03 
GeneralFile Path functions Pin
Bud Pass18-Sep-05 13:39
memberBud Pass18-Sep-05 13:39 
GeneralRe: File Path functions Pin
gpmaker18-Sep-05 13:41
membergpmaker18-Sep-05 13:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 27 Sep 2005
Article Copyright 2005 by gpmaker
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid