Click here to Skip to main content
15,867,308 members
Everything / General Programming / String

String

string

Great Reads

by Michael Sydney Balloni
Different languages and approaches are evaluated for a file and string processing benchmark
by fabio bussu
MatchKit is a .NET Library that provides a set of classes to build patterns to match simple and complex strings
by honey the codewitch
How to provide custom formatters for string.Format() in C#
by honey the codewitch
BinaryReader needs a better way to read strings and types. Here's a quick and dirty fix

Latest Articles

by Xavier Junqué i de Fortuny
Converts MathML coded string to/from plain text string
by Jovibor
String to number conversion library, for char and wchar_t strings
by Michael Sydney Balloni
Different languages and approaches are evaluated for a file and string processing benchmark
by Brian C Hart
Example of how to use the caret (^) in Regexes that have specific matching requirements

All Articles

Sort by Score

String 

13 Mar 2020 by honey the codewitch
How to provide custom formatters for string.Format() in C#
23 Apr 2021 by honey the codewitch
BinaryReader needs a better way to read strings and types. Here's a quick and dirty fix
12 Apr 2015 by Jeffijoe
Writing properly formatted, grammatically correct, translatable UI messages
18 May 2010 by xprog
Algorithm to convert Arabic Numbers to Arabic Text using C#
27 Jan 2015 by HiDensity
Class providing methods to count up a string using a definable character set.
2 Feb 2011 by M@dHatter
PHP Magic String Builder with Append Format.
29 Jun 2011 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...
30 Oct 2011 by steveb
In UNICODE:CString str = L"Test";std::wstring ws(str);std::string s;s.assign(ws.begin(), ws.end());
16 Dec 2011 by Pascal Ganaye
A custom C# string implementation that stores its data in a UTF8 byte array.
18 Jan 2012 by Namlak
string blah = string.Join(",", cities.Select(c=> c.Name));
24 Jan 2012 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...
9 Jul 2012 by Matt T Heffron
This is an alternative for "Custom String FormatWith using Reflection"
10 Jun 2010 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...
13 Nov 2010 by Andrianov
How to run makecert only in command string mode?
7 Mar 2011 by #realJSOP
Extension method that checks for a properly Xaml-ized string
26 Jun 2011 by JP_Rocks
A tip to concatenate a set of strings using comma/pipe
1 Nov 2011 by Kaqkk79
How about this (assuming your project is set to Unicode)?CString strMyString=L"Test string";std::string strMyStdAnsiStr = CStringA(strMyString);
7 Feb 2011 by Fatih P.
Here is the one i wrote sometime ago/* ---------------------------------------------------------------------------- * Teknober.com - All rights reserved * ---------------------------------------------------------------------------- * File Name : TStringBuilder.php * Section ...
18 Apr 2011 by cluengas2k
Microsoft SQL Function To Proper Case A Name From A Given String
29 Jun 2011 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...
30 Jun 2011 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) { ...
1 Dec 2011 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...
24 Feb 2012 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
18 Apr 2012 by Andreas Gieriet
This is an alternative for "String.Insert - insert a separator on given positions"
3 Feb 2013 by George Swan
This is an alternative for "Dictionary.BestMatch"
U 25 Mar 2024 by Xavier Junqué i de Fortuny
Converts MathML coded string to/from plain text string
7 Apr 2011 by oleg63
CString m_Name;CT2CA pszName(m_Name);std::string m_NameStd(pszName);Works for me everywhere... :)
14 Dec 2013 by Shweta Lodha
How to format strings in binding
2 Apr 2011 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...
5 Mar 2011 by DrABELL
Algorithms extending the System.Globalization.TextInfo.ToTitleCase Method
2 Jan 2014 by Viktor Kovács
A simple solution for processing spaceless strings
29 Feb 2012 by Tieske8
Fast conversion between strings and byte arrays, while bypassing the codepage limitations
16 Nov 2014 by D Sarthi Maheshwari
Extension method on String class to convert string to IConvertible structs and nullable types
13 Nov 2011 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.
18 Jan 2012 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...
26 Jun 2019 by DiponRoy
Create hash and compare
12 Feb 2015 by FrostedSyntax
Regex patterns that will condense multiple spaces, tabs or line breaks into a single space, tab, or line break.
17 May 2010 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...
24 Jan 2012 by Mikhail-T
A short one-line way to convert Array or List of any data into custom string via LINQ
8 Jun 2010 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...
31 Oct 2013 by R%S
Adding stuff to your logs.
27 Jun 2011 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) { ...
26 Apr 2015 by arora.abhishek
In this tip, you will learn about the new features of C# 6.0 String Interpolation.
23 Feb 2012 by PIEBALDconsult
An Extension Method that is similar to String.StartsWith, but uses a StringComparer
27 Mar 2015 by PIEBALDconsult
Extension methods to select a Dictionary entry using StartsWith
6 May 2015 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.
30 Dec 2010 by santosh poojari
To remove or replace multiple special character from string using sql queries.
16 Jun 2020 by honey the codewitch
Easily word wrap strings of text in C#
28 Feb 2010 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...
30 Jan 2015 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.
15 Sep 2015 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.)
17 Jan 2011 by Maxim Fedotov
Presents StringFormat methods with string (not integer) keys in 'format' string.
12 Jun 2010 by Alain Rist
A set of C++ functions to load the resource into an existing string or build the string from it
10 Feb 2016 by Kouji Matsui
This library is simple and is a substitution of System.String.Format.
23 May 2012 by Shweta Lodha
Performance analysis for String and StringBuilder
5 Jul 2012 by Sumit Chawla
Custom String FormatWith using Reflection
15 Apr 2013 by Kimahari
Morse code encryption.
3 Apr 2012 by Mikhail-T
Tutorial on how to create simple extension that converts view model propety name to string
21 Jan 2015 by Bhis
Read XML File and change date contents
20 Aug 2022 by Brian C Hart
Example of how to use the caret (^) in Regexes that have specific matching requirements
17 May 2010 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...
12 Aug 2010 by jfriedman
public static class StringExtensions { public static bool IsNullOrWhitespace(this string s) { if (null == s) return true; return string.IsNullOrEmpty(s.Trim()); } }
29 Mar 2011 by CalicoSkies
C++: Converting an MFC CString to a std::string
22 Oct 2010 by TweakBird
Common Mistakes Made by Programmers
30 Jan 2014 by Tomer Weinberg
A piece of code you can copy paste to transform TimeSpan into user readable UI text
24 Jan 2012 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());
18 May 2012 by ♥…ЯҠ…♥
Convert PDF content into text using C#, for beginners.