Click here to Skip to main content
15,891,908 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 Updated

String 

19 Oct 2010 by "Fish" (David B. Trout)
Simple parsing of VS_VERSIONINFO version information strings displayed in an XP-style file-properties "Version" tab
13 Jan 2010 by #realJSOP
Put pointy brackets around it and parse it like XML with Linq-to-XML. Just treat everything like an Attribute.// our original stringstring text = "screen_fadetimeout=\"0\" font=\"Courier New\" fontsize=\"11\" linesize=\"4\" theme_color1=\"-1518056\" theme_color2=\"-9674238\"";// add our...
11 Jan 2011 by #realJSOP
It's certainly the fastest way to type it.If you want to try to find faster ways, be a programmer and try different ways to approach the problem.Performance for such a task would greatly depend on the length of the string involved.
12 Jan 2011 by #realJSOP
This is one way:string x = sb.ToString();foreach (char ch in x){ seriealPort1.Write(ch);}Or, to use your sample:[EDIT]StringBuilder sb = new StringBuilder();foreach (Char c in textBox1.Text){ sb.Append(c); serialPort1.Write(c.ToString()); if...
7 Mar 2011 by #realJSOP
Extension method that checks for a properly Xaml-ized string
27 Feb 2018 by #realJSOP
Spell it out! No! Wait!
26 Jan 2017 by #realJSOP
str = str.Replace("'", "\"");
20 Feb 2018 by #realJSOP
Depending on the type of number it is, you could use xxx.TryParse() (where "xxx" is the numeric data type in question). string x = "1234"; string y = "-1234"; string z = "12b34"; int value; if (int.TryParse(x, out value)) { // x is indeed a valid integer, so...
16 Oct 2018 by #realJSOP
Well, each column appears to be a fixed width, so simply figure out how many characters wide each column is, and for each string in the file, do a Trim(Substring(line, x, y)) where x is the index into the string to start in, and y is the width of the column. Don't forget to NOT parse anything...
8 Dec 2014 by /\jmot
Full Description here..http://www.dotnetperls.com/querystring[^]
24 Apr 2021 by _-_-_-me
Here, I tried to read the string literal using scanf() function. When I tried to print the string literal using printf() function , I am getting the output as (null). Why is that so? why I am not getting the string literal which I have read...
3 Dec 2017 by ________________
private static int [] CountSpaces(string inputString) { List result = new List(); int ss = 0;//space local counter for (int ii = 0; ii
2 Aug 2012 by _Amy
Hi,You are converting your string to byte and again displaying it in string format?The string representation of byte will be big in length and size anyway. Store it in byte only.--Amit
5 Mar 2014 by _Asif_
Check below url for multiple solutions.How To Change DataType of a DataColumn in a DataTable?[^]One solution could also be to use Typed Data table. Search google for more details
26 May 2015 by _Asif_
Try regular expression with [0-9]+. There are tons of information present, you just need to google!Regards,Asif
13 Jan 2022 by _Asif_
you are receiving XML as response instead of JSON that is why following line is giving exception. JSONObject jsonObject = new JSONObject(response); You need to change these two lines JSONObject jsonObject = new JSONObject(response);...
17 Feb 2022 by _Asif_
Although (MS_FT_)([A-Z]+[0-9]*(_[A-Z])*)(_T) regex seems not very promising but it can give you a good start. Try this public class Example { using System; using System.Text.RegularExpressions; public static void Main() { ...
5 Jun 2013 by _Damian S_
Putting the variable applicationdate in quotes like this "applicationdate" causes VB.NET to treat it like a string. If it's a variable, don't use quotes.
18 Mar 2013 by _Maxxx_
Solution - make sure the string is in the correct format.
6 Jun 2015 by _Q12_
I have checkedListBox1 control. I want to write into a string "checked3487", ONLY the checked checkboxes text. (the text near the checkbox).When I press one checkbox, "The check state is not updated until after the ItemCheck event occurs", but the "if (e.NewValue == CheckState.Checked)" is...
6 Jun 2015 by _Q12_
Now is working!it was a string manipulation after all. Damn it.I got inspired and I find the solution.here it is: if (e.NewValue == CheckState.Unchecked) { if (checkedList.Contains(checkedListBox1.Items[e.Index].ToString())) { ...
1 Oct 2017 by A_Griffin
My JavaScript is pretty ... ahem, basic.... but I enjoy getting there in the end! :) Here's a simple HTML page that does it - no doubt those who know about these things ca do it far better, but I hope this helps you learn something... ...
1 Oct 2017 by A_Griffin
Here's a much shorter version - I was going round the houses unnecessarily above.... function isNumeric(n) { return !isNaN(parseInt(n)) && isFinite(n); } function solveMe() { var sOut = '' //...
6 Jun 2014 by Aamir Yousafi
I'm using Dev C++ 5.5.3 and the code below compiles just fine but as soon as I enter input, my program's .exe crashes.#include #include #include main(){ int length; char *strng, *strng2; printf("\nPlease enter a simple phrase with no...
24 Jun 2014 by Aamir Yousafi
I finally got it working the way it needs to work! Thanks all!#include #include #include main(){ /* pre-run-time declarations */ unsigned int dynlen = 256; int i = 0, ch = 0, j = 0; char *strng = (char*)malloc(dynlen); /* ask...
14 Jul 2016 by aamir_shaheen
I am developing a windows phone app which requires some string manipulation. but its still really hard for me to find proper code for that, I also triedMicrosoft.Visualbasicbut nothing there.let suppose I have two string variablesDim var1 as String="123456789"Dim var2 as...
5 Dec 2012 by Aarti Meswania
1. using linqhttp://www.functionx.com/csharp/linq/Lesson11.htm[^]2. using sqlselect distinct list1.a + list2.a + list3.a as Combination from( select 'a' as a union all select 'b' as a union all select 'c' as a) as list1cross join( select '1' as a union all select '2' as a...
5 May 2015 by Aashir Khan
I am a fairly new programmer in Java. My question is...for the following text file contents:http://textuploader.com/ga7xI am trying to parse the book reference numbers (the integers) and the book titles (the strings) using a bufferedreader into separate arraylists and then later on...
13 Nov 2022 by Aayush Jain 2022
a = 95 print(type(a)) a = str("a") print(type(a)) a = int(a) print(type(a)) What I have tried: I tried to convert int to string and than string to int I am facing issue on converting string to int
7 Feb 2013 by Abdulmateen50
To display a number with its associated currency symbol and the appropriate number of decimal places we use the currency character “C” or “c”, like:Console.WriteLine("{0:C}", 1.2");The number 1.2 appears in the output like this: $1.20.my question is what does "0" indicates in {0:C}??
14 Jun 2012 by Abey Kuruvila
Hi!I need help.I want to format part of a String for a DataGridViewCel in vb.net.The thing that I'm doing is, inputting details of a person in a datagridview.So the data is supposed to be formatted with different fonts and then displayed on the DGV cell.SO bascially my data consists...
8 Oct 2012 by Abhi KA
progress billings made to meet project requirements will be invoiced when applicable and subject to the same terms. In the event it shall become necessary for {{businessName}} to enforce any of the provisions of this agreementi need string v1="progress billings made to meet project...
27 Nov 2016 by Abhijit Parab
Hi,I am storing the huge dataset in the session variable. which is causing the performance of the application. As the dataset has the information which is specific to the user hence cannot store this huge data in cache object.Now I am converting this dataset into xml and storing into the...
18 Nov 2016 by Abhilash.J.A
I have create Set up file for WPF application and the database is SQLite DB. After the installation the SQLite DB is located this path in C folder, and the application is running properly on any computer that without an administrator Password PC.C:\Program Files...
12 Sep 2010 by Abhinav S
Will operator overloading be of any help to you[^]?
11 Oct 2010 by Abhinav S
You need to provide some code or at least tell us what you have done.Just providing the error you got does not help a bit in anyone trying to resolve it.
27 Nov 2010 by Abhinav S
See here[^].If you can get an array back (containing all the differences as is provided by the author here), you can calculate the percentage by calculating the differences versus the original string lengths.
1 Feb 2011 by Abhinav S
To create substrings via regex, see here[^].
30 Apr 2011 by Abhinav S
Try putting @ before your text string paths.
28 Dec 2011 by Abhinav S
TryHow to export to Excel from vb.net code. [^]Export to Excel using VB.Net[^]
1 Jan 2012 by Abhinav S
This article[^] should give you a fair idea of what you need to do.The sample is in VB.Net and should help you out.
2 Jan 2012 by Abhinav S
blemail.Text = Request.QueryString("email").ToStringEnsure that you have a querystring parameter with the name email.This appears to be null and converting a null to a string is throwing the error.To remove the error, you can use Convert.ToString(Request.QueryString("email"));.This...
26 Mar 2012 by Abhinav S
Here[^] is the hewbrew character set that you can capture in your keydown event.The unicode range is \u0590 to \u05FF.
20 Apr 2012 by Abhinav S
Using RegEx could be an approach that you could consider - http://www.dotnetperls.com/regex-match-vbnet[^].
6 Aug 2012 by Abhinav S
You need to change the box's font style.http://www.java2s.com/Code/CSharp/GUI-Windows-Form/RichTextBoxFontbolditalic.htm[^] might help.how to change a textbox text to bold,italic in C# windows application[^] is for a normal textbox, but might give you an idea as well.
16 Jan 2013 by Abhinav S
Try debugging your code to see for what text you get this error.This will help you correct issues with data (or your code).
10 Apr 2013 by Abhinav S
Tryfunction makex(howMany){console.log("The parameter was "+howMany);string t;for(var x = 0; x
31 Jan 2014 by Abhinav S
Similar commands exist in vb.net.Try String Manipulation[^].
31 Jan 2016 by Abhinav S
Try string strResult=strValue.PadRight(N, '0');
1 Jun 2014 by Abhishek Pant
http://www.dotnetfunda.com/interviews/show/3832/difference-between-string-and-string-in-csharp[^]http://stackoverflow.com/questions/7074/whats-the-difference-between-string-and-string[^]
12 Jan 2010 by Abhishek Sur
Why dont you split the element by space to create an array of all name/value collection and change the value of each those strings.After that recreate the entire string again.You can also use regular expression to do this... :)
11 Dec 2012 by Adam R Harris
You need to format the column in excel. have a look at this: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/fdc6cfb5-e7cc-466f-95f0-d8cd29f49d2d/[^]
13 Jul 2014 by addy25
Hey guys,I want to send a test message out to a list of people, however I want the message personalized each time.This ive done however im getting two errors in with my code:1:The best overloaded method match for Mailing.Mailing.SendEmail(string, string,...
21 May 2012 by adkalavadia
please refer below link for html tag stripping.for C# : Convert HTML to Plain Text[^]HTML Tag Stripper[^]for SQL : MS SQL Function[^]
3 Jun 2014 by adriancs
string is an alias for System.String. So technically, there is no difference. It's like int vs. System.Int32.As far as guidelines, I think it's generally recommended to use string any time you're referring to an object.e.g. string place = "world";Likewise, I think it's generally...
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...
21 May 2012 by Aescleal
Repeat after me..."When I do a search in C++ and I don't use std::sort and std::find I shall go and punch myself in the head OR, preferably as I don't like pain, I shall rewrite my class so it can be put in a collection and sorted and searched."Having said that, how can you write a class...
30 Oct 2013 by Aescleal
Try using std::map first. Yep, the performance is rubbish but often you can't tell the difference between optimal and rubbish when you've got a small number of things (less than thousands) to choose between. Another thing you might want to try is std::unordered_map as you can then write portable...
7 Mar 2015 by Afzaal Ahmad Zeeshan
This article is for the concept of Random URLs and how they can be generated in ASP.NET for creating Random URLs for your application.
8 Dec 2014 by Afzaal Ahmad Zeeshan
You can use UrlData objects to get the data from the Url, for example if the URL to the page where you would read the name is like http://www.example.com/page/MyNameHereThe code to get the MyNameHere would be like this, var name = UrlData[0]; // first item in the Url, You can...
15 Nov 2015 by Afzaal Ahmad Zeeshan
The answer is very much simple, in the realm of C++, it already has replaced the printf function. You write the C++ programs like this, #include void main () { std::cout
19 Mar 2016 by Afzaal Ahmad Zeeshan
Hardcoded string are the literal strings. So, What you may be referring to is, literal strings in the data.// Instead ofvar myStr = Home + "123";// Using thisvar myStr = "Test123";The problem doesn't show up, unless we have to use this string literal in multiple places. If you...
11 Dec 2018 by Afzaal Ahmad Zeeshan
Quote: I need to search one directory (c:\K_txt) of almost 3,000 .txt files Searching this on the fly is a really very bad idea, and would have to make your users wait each time they make a change in the query. A good approach would be to read your files once, and create tokens (words, in...
2 Jun 2014 by agent_kruger
I have a unicode number "U+2602", how to convert it into it's particular symbol or charachter and then again convert it back to unicode number? Symbol of the above unicode number is :- (Please see in the link below) https://www.dropbox.com/s/9n8v8rs383he7e3/Unicode%20answer.png[^]
14 Aug 2014 by agent_kruger
i have a string of length 98975333 and i need to remove first 5 letters in it. Can anyone suggest the best way to do this keeping performance in mind?I triedstr.Substring(5,str.Length);str.Substring(0,5);which gives me result in 0.29 secbut i want something even faster than the...
8 Oct 2013 by Ahmed Jubayer
You can try this link:http://forums.asp.net/t/1726067.aspx[^]
26 Feb 2014 by ahmetkocadogan
Hello there. I have to read a .txt file that has fixed line lenght. Think this line lenght is 12. Below is an example of this .txt :-first line-second line-third line continues-fourh l.....If lenght of a line is bigger than it's fixed lenght, it's written to a new line....
13 Sep 2010 by aidin Tajadod
Hi,As I know there is no equivalent for eval (like vb6) in c#. but you can use system.CodeDom.Compiler namespace to create your own eval function. by using that you can compile your code on the fly and use it in your program.
11 Oct 2010 by aidin Tajadod
hi, use split function.var sEmails=inEmail.split("@");var use=sEmails[0];var domain=sEmails[1]; Hope this can help you.
28 Nov 2014 by Ainy Mughal
Try this.TimeSpan time = TimeSpan.Parse(timeString)
19 Apr 2012 by Ajay Vijayvargiya
Many Windows C++ programmers get confused over what bizarre data type identifiers like TCHAR and LPCTSTR are. Here, in brief, I will try to clear out the fog.
1 Apr 2018 by Akhil Jain
i have a string in which i am using String.format in this i want to remove the 2nd parameter if string iteration will come as ="" or NULL and also want to remove the . AND [Source].[System.IterationPath] IN ('{1}') from the String that will be formed. is there any way besided the String format...
4 Nov 2016 by Akhilesh Chauhan
suppose I have to accept an mathematical expression in a string format from the user, like e.g. 2*5 or 9/5+9 or 91-10+82/3 and so on. It can be of any length. It works if I have single length operand like 3+9-5*4/2 by some change in my below code it works fine. but fails if i give it more then...
4 Nov 2016 by Akhilesh Chauhan
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplicationExpressionUsingWhileLoop{class Program{ static void Main(string[] args) { char[] arrOne = new char[100]; int[]...
5 Oct 2012 by Akinmade Bond
This worked for me.q = "15.Crank vs.Cams Bank 2"; // The variable to split. string s= q.Substring(txtsplit.Text.IndexOf('.')); //Get the text after the first '.' string[] v = s.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); foreach...
24 Apr 2019 by AKJKTM
Create a C# library project that calculates the total area of all shapes in a collection. Details For simplicity, two types of shapes are required below Circle Rectangle Support of adding different types of shapes in the future with minimum change to code is desired. Each shape object contains...
20 Oct 2013 by aks.shan
Hey All,I have a textbox.In that some entries are made liketextbox.text = Tendulkar,Sachin(srt);Dhoni,MS(msd);Sehwag,Virender(viru);D'Souza,Tim(tdsc)I want an array of string which will have values like (srt,msd,viru,tdsc).I guess we will first have to go around splitting by (';')...
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
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...
5 Apr 2014 by Alex Houben
Hi,I use the following code:namespace wpfEmun{ enum Seizoen { lente , zomer, herfst, winter, autumn = herfst, spring = lente, summer = zomer }; public partial class Form1 : Form { public Form1() { InitializeComponent(); } ...
8 Mar 2018 by Alex the Green Apple
C library defining string type and string manipulation functions
7 Oct 2010 by alexhairyman
Alright, This is my first post on codeproject, so excuse any errors in format please.I am trying to create a gui application for Robocopy and eventually 7z. Last night I got my code to work and the application ran fine. Today I created a new project to make use of some new devexpress...
4 Jul 2012 by Ali_100
at run time we can have any path from below,path=d:\abxyz.xmlpath=d:\abcmn\a\xyiopoipoz.xmlpath=d:\abc\a\bsa\xysaz.xmlI want to get only the name of XML file.. mean that i want to ignore the string till last \....rite now i am hardcoding by path.substring(#).Thanks in advance
17 Nov 2017 by Alma Konde
Hello, couldn't you please advise me how to create a string 2 dimensional array and copy there the data from the csv file. This code is not creating string data[,] array and do not copy the data from the csv file in the loop. What I have tried: using System; using System.IO; using...
28 Oct 2015 by Am Gayathri
Am trying to change the number format of a value in a data table. Am using String.Format("{0:n}", number) method to change the number format but it doesn't work.Below is my code, foreach (DataRow dr in datasetx.Tables[0].Rows) { ...
5 Mar 2014 by Amalraj Ramesh
Try thisDataView dataview = yourdatatable.DefaultView;dataview.Sort = "ColumName";DataTable dt = dataview .ToTable();
15 Mar 2017 by Amien90
var variable = app.GetVariableList(); app.Variables = new List(); foreach (variableItem in variable.Items) { ListVariables VariableResult = new...
14 Mar 2017 by Amien90
Sample is in the first postinput string : D:\Location\$(Variable1).Txtoutput string : D:\Location\Test.Txt
16 Feb 2017 by Amir Hossein Hmd
Hi guys, (i'm a beginner :) i defined a variable (string = userSecondInput) in the do-while loop ("do" part), but i can't use the variable in the "while"! why? :(please help me :( i'mWhat I have tried: Console.WriteLine("Please Enter Your name: "); string...
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.
27 Nov 2010 by amit_upadhyay
i want to compare two strings and calculate the percentage of difference between them. This could have been easier for two strings of same length. But what if the length is different? For eg :hello my name is amit and i like to help everybodyhi my name is amit and i would like to help...
5 Oct 2012 by AmitGajjar
Hi,Here is the improved version of Solution1,string result;string fileName = "15.Crank vs.Cams Bank 2"; // The variable to split.string[] v = fileName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);for(i =1; i{ result += v[i];}Here in for loop...
6 Apr 2013 by AmitGajjar
Hi,Although everyone gives the correct answer. i would like to add more. Error it self says what is the problem. The line where you are having issue is using filterQuery variable. Either you can assign default value of the string at the time of declaration or you need to add some...
15 Feb 2014 by Ammar Shaukat
i'm trying this code to copy last part on string which contain year...so i would be able to calculat age from this...string DOB = "10/10/1992"string Year = "";int j=0;for(int i = 5 ; i
11 Apr 2013 by Amogh Natu
You can validate that in javascript. Use the following code. function Validate() { var txtValue = document.getElementById("MainContent_txtTestBox").value; var checkFlag = isNaN(txtValue); if (!checkFlag) { return...
11 May 2013 by Amogh Natu
Hi, I'm trying out a sample problem on strings wherein I take a string as input and find out the similarity of each of its suffix with itself. For two strings A and B, the similarity of the strings is the length of the longest prefix common to both strings. For example, the similarity of...
30 Aug 2020 by Amy Zhou
What the class describes is about "reversing a string", which is correct and usable from the Leetcode website. Today, I want to present "reversing a string" by inputting a value by myself (such as the int main() part below), but I still can't...
9 Jul 2018 by an0ther1
Check the Setting Type. Application Settings cannot be updated without a custom handler - refer; Application Settings Overview | Microsoft Docs[^] Use your debugger, if the setting is defined but not initialised, it will be null & you cannot add values to it - the blow code works in a Test...
10 Feb 2023 by Anand 2023
I am unable to understand this problem....please make me understand and write a program to solve this question What I have tried: I don't have idea how to tackle this question.
14 Aug 2023 by Andre Oosthuizen
I will use regular expressions to match the key-value pairs in your input string, others might disagree with me. :) I have created a fiddle for you at - Reading string values in C#[^] using System; using System.Text.RegularExpressions; public...