Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Everything / programming / string

String

string

Great Reads

by Sarang Date
Any string input can have these many possible states1) String is null2) String is empty3) String contains nothing but white space4) String has some contentTill now, .NET had static method for stringbool string.IsNullOrEmpty()which handled first two conditions for...
by jfriedman
public static class StringExtensions { public static bool IsNullOrWhitespace(this string s) { if (null == s) return true; return string.IsNullOrEmpty(s.Trim()); } }
by Ben Hall (failingfast.io)
It's worthwhile knowing the what, when and why to improving string comparison performance. In this article, I will explore one way, string interning.
by JesseChisholm
FormatEx is a method that allows structuring formatting placeholders indirectly from arguments.

Latest Articles

by Sarang Date
Any string input can have these many possible states1) String is null2) String is empty3) String contains nothing but white space4) String has some contentTill now, .NET had static method for stringbool string.IsNullOrEmpty()which handled first two conditions for...
by jfriedman
public static class StringExtensions { public static bool IsNullOrWhitespace(this string s) { if (null == s) return true; return string.IsNullOrEmpty(s.Trim()); } }
by Ben Hall (failingfast.io)
It's worthwhile knowing the what, when and why to improving string comparison performance. In this article, I will explore one way, string interning.
by JesseChisholm
FormatEx is a method that allows structuring formatting placeholders indirectly from arguments.

All Articles

Sort by Score

string 

by Sarang Date
Any string input can have these many possible states1) String is null2) String is empty3) String contains nothing but white space4) String has some contentTill now, .NET had static method for stringbool string.IsNullOrEmpty()which handled first two conditions for...
by jfriedman
public static class StringExtensions { public static bool IsNullOrWhitespace(this string s) { if (null == s) return true; return string.IsNullOrEmpty(s.Trim()); } }
by Pascal Ganaye
A custom C# string implementation that stores its data in a UTF8 byte array.
by honey the codewitch
BinaryReader needs a better way to read strings and types. Here's a quick and dirty fix
by PIEBALDconsult
An Extension Method that is similar to String.StartsWith, but uses a StringComparer
by Andreas Gieriet
This alternative is not substantially different, it simply splits the function into two:one for clippingone for comparingpublic static string ExtClipRight(this string a, int n){ return (n < 0 || a.Length <= n) ? a : a.Substring(0, n);}...public static bool...
by Code-o-mat
Combo boxes under Windows have a "nice" feature of automatically selecting an item for the user when the user drops down the list of the combo box. This selection is based on partial string matching by the combo box, namely, it will select the first item in the list -if any- that begins with the...
by HiDensity
Class providing methods to count up a string using a definable character set.
by DiponRoy
Create hash and compare
by CalicoSkies
C++: Converting an MFC CString to a std::string
by jean Davy
As you use CString, you have access to the CW2A ATL macro, assuming that you work with _UNICODE defined, here it is:CString theCStr;...std::string STDStr( CW2A( theCStr.GetString() ) );which will convert to "system encoding on the user's machine" (thanks Nemanja[^] comment !), if you...
by oleg63
CString m_Name;CT2CA pszName(m_Name);std::string m_NameStd(pszName);Works for me everywhere... :)
by steveb
In UNICODE:CString str = L"Test";std::wstring ws(str);std::string s;s.assign(ws.begin(), ws.end());
by Kaqkk79
How about this (assuming your project is set to Unicode)?CString strMyString=L"Test string";std::string strMyStdAnsiStr = CStringA(strMyString);
by geoyar
I am using CString str(_T("Test"));typedef std::basic_string string_t;string_t resStr(str);It works because the CSting has a cast to LPTCSTR.
by stonexin
LPSTR WideChar2MBCS( const CString& strCS ){ const UINT wLen = strCS.GetLength() + 1; UINT aLen = WideCharToMultiByte(CP_ACP,0,strCS,wLen,NULL,0,NULL,NULL); LPSTR lpa = new char[aLen]; WideCharToMultiByte(CP_ACP,0,strCS,wLen,lpa,aLen,NULL,NULL); return...
by Tomer Weinberg
A piece of code you can copy paste to transform TimeSpan into user readable UI text
by TweakBird
Common Mistakes Made by Programmers
by xprog
Algorithm to convert Arabic Numbers to Arabic Text using C#
by ♥…ЯҠ…♥
Convert PDF content into text using C#, for beginners.
by Mikhail-T
Tutorial on how to create simple extension that converts view model propety name to string
by Mikhail-T
A short one-line way to convert Array or List of any data into custom string via LINQ
by Namlak
string blah = string.Join(",", cities.Select(c=> c.Name));
by wgross
I would just use:string.Join(",", cities.Select(c=>c.Name))Since Version 4 of the Framework there is an overloaded versions of string.Join for IEnumerable too. It uses a StringBuilder internally and doesn't insert a seperator after the last element as well.I could't find the Join method...
by Richard Deeming
If you're stuck with .NET 3.5, you can use the Aggregate extension method[^]:string cities_string = cities.Aggregate(new StringBuilder(), (sb, c) =>{ if (0 != sb.Length) sb.Append(", "); sb.Append(c.Name); return sb;}, sb => sb.ToString());
by WajihUllahBaig
Hi there,Its been a while since I wrote my last article. Since got myself into a problem of getting the system name of my PC.I dragged my C instincts into the MSDN world of asking how to get the PC name.After fiddling for a while I got hold of the PC name, not that difficult as a...
by Alain Rist
You might have considered using ::GetComputerNameA() which does the conversion for you:std::string GetSystemName(){ CHAR sBuf[MAX_COMPUTERNAME_LENGTH + 1] = {0}; DWORD dwLen = MAX_COMPUTERNAME_LENGTH; ::GetComputerNameA(sBuf, &dwLen); return std::string(sBuf);}Note...
by Sumit Chawla
Custom String FormatWith using Reflection
by Matt T Heffron
This is an alternative for "Custom String FormatWith using Reflection"
by George Swan
This is an alternative for "Dictionary.BestMatch"
by PIEBALDconsult
Extension methods to select a Dictionary entry using StartsWith
by Shweta Lodha
How to format strings in binding
by Shvetsov Evgeniy
How to generate a random sequence of chars with the specified parameters (e.g., length, char sets, char count per set, etc.)
by Viktor Kovács
A simple solution for processing spaceless strings
by R%S
Adding stuff to your logs.
by Andrianov
How to run makecert only in command string mode?
by M@dHatter
PHP Magic String Builder with Append Format.
by Fatih P.
Here is the one i wrote sometime ago/* ---------------------------------------------------------------------------- * Teknober.com - All rights reserved * ---------------------------------------------------------------------------- * File Name : TStringBuilder.php * Section ...
by honey the codewitch
How to provide custom formatters for string.Format() in C#
by Kimahari
Morse code encryption.
by #realJSOP
Extension method that checks for a properly Xaml-ized string
by DrABELL
Algorithms extending the System.Globalization.TextInfo.ToTitleCase Method
by Alain Rist
A set of C++ functions to load the resource into an existing string or build the string from it
by Aescleal
Alain's (original, now much hacked) narrow character version, could leak if std::basic_string::asign threw. To make the function exception safe either use a local buffer (if the size is fixed) or a vector (if the size isn't known).In both cases it's usually more efficient (and readable) to...
by Xavier Junqué i de Fortuny
Converts MathML coded string to/from plain text string
by cluengas2k
Microsoft SQL Function To Proper Case A Name From A Given String
by FrostedSyntax
Regex patterns that will condense multiple spaces, tabs or line breaks into a single space, tab, or line break.
by Kouji Matsui
This library is simple and is a substitution of System.String.Format.
by Shweta Lodha
Performance analysis for String and StringBuilder
by Jeffijoe
Writing properly formatted, grammatically correct, translatable UI messages
by Bhis
Read XML File and change date contents
by Brian C Hart
Example of how to use the caret (^) in Regexes that have specific matching requirements
by Amir Mohammad Nasrollahi
In this article, i consider the problem of identifying motifs in the biological sequence data sets. To solve this task, i present a new algorithm for finding patterns that just use library in C compiler and a new way to avoid using arrays search.
by honey the codewitch
Easily word wrap strings of text in C#
by JP_Rocks
A tip to concatenate a set of strings using comma/pipe
by Mohammad A Rahman
The idea was good, but I think we could probably do something like below:public static string UsingStringJoin(IEnumerable sList, string separator){ return sList.Any() ? string.Join(separator, sList.ToArray()) : string.Empty;}public static string...
by Mario Majčica
Or even better:public static string Join(this IList list, string joinString) { StringBuilder result = new StringBuilder(); int listCount = list.Count; int listCountMinusOne = listCount - 1; if (list != null && listCount > 0) { ...
by Erich Ledesma
I rather like IEnumerable than IList, parameters should be as general as posible. I think it's really getting very fun up here. Here's my choice, just for strings.public static string Join(this IEnumerable parts, string separator){ if (! parts.Any()) return...
by George Swan
You can use the Aggregate method with a StringBuilder. I've modified Eric's alternative in order to save a bit of code. Only one return statement is needed as an empty StringBuilder returns an empty string.public static string Join(this IEnumerable parts, string separator) { ...
by arora.abhishek
In this tip, you will learn about the new features of C# 6.0 String Interpolation.
by Tieske8
Fast conversion between strings and byte arrays, while bypassing the codepage limitations
by jocko3d
The TestConversion function is not valid. The line of code "data = data & Chr(n)" uses the Chr function to build a string of characters used for the test. The problem is that the Chr function is itself bound to a code page. Specifically, it will utilize the code page that is in use by the...
by Andreas Gieriet
This is an alternative for "String.Insert - insert a separator on given positions"
by D Sarthi Maheshwari
Extension method on String class to convert string to IConvertible structs and nullable types
by Maxim Fedotov
Presents StringFormat methods with string (not integer) keys in 'format' string.
by santosh poojari
To remove or replace multiple special character from string using sql queries.
by FrostedSyntax
Learn how to use regular expressions to find addresses or parts of an address in a given string. These patterns can also be used to verify that a given string is a true address.