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

U 30 Apr 2024 by Xavier Junqué i de Fortuny
Converts MathML coded string to/from plain text string
13 Mar 2024 by Jovibor
String to number conversion library, for char and wchar_t strings
24 Nov 2023 by PinkGoat_
So I have a button made from my xaml file (view), called Export. When the user clicks on it, the logs created during the run of the app get exported to Logs.txt. If there are Warnings, Errors or Exceptions, those will instead be created in...
24 Nov 2023 by Graeme_Grant
The best solution, IMHO, would be to create a custom log provider. You can then handle the logging as the log entries are added. I wrote an article for a custom Log Viewer control that has a custom Log Provider, one for each of the 4 common...
17 Nov 2023 by cheekycroak
I had another expert help me to resolve the issue. Below is the code for any future reference in case anyone is stuck like me. Appreciate everyone's help and time to reach a solution. $url = trim($playlistSong->filename); $url =...
17 Nov 2023 by cheekycroak
The code filename; ?> reads the path from a database table. In order for the html5 player to play the song it requires the local path that resides in the database table to be converted to an absolute URL path. The...
15 Nov 2023 by Andre Oosthuizen
Richard has given you a close to perfect solution but it returned the same path to your D: drive as to where you wanted a result of the online url, I have edited it a little which results in the exact output you require. I have hardcoded your...
14 Nov 2023 by Richard MacCutchan
It appears that the str_replace function sees the sequence \200 and removes it. As the result from your code gives: https://mywebsite.com/Music0 Hits/Album.Mp3 So using the following code: $url = "D:\Music\2000 Hits\Album.Mp3"; $urlb...
7 Oct 2023 by User 16071582
def compute_next(pattern: str) -> list: """ Compute the 'next' array for the KMP algorithm. Args: pattern (str): The pattern (substring) for which to compute the 'next' array. Returns: list: The computed 'next'...
21 Sep 2023 by Richard MacCutchan
Lots of information at The Python Tutorial — Python 3.10.12 documentation[^]. Or if you really do not understand the question then ask your mentor.
21 Sep 2023 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, this is part of your grades and it wouldn't be at all fair for us to do it all for you. So we need...
21 Sep 2023 by li wilde
Given a pattern p to be a string, and the target string target, output the total number of patterns in the target string target p will only be number characters and target will only be lower case characters Runtime: 5s Test case: 2≤...
8 Sep 2023 by Stylus STYLUS
I create app and all work fine. Need to replace string instead of local database to be cloud database Data in table database is the same. New string is: Data Source=94.251.1.1,1433;Initial Catalog="BCC";User ID=admin;Password=admin What I...
8 Sep 2023 by CHill60
It's not clear at all why you are having a problem - if you could type in the original connection string then you can overtype it with your new one. Perhaps one of these resources will help you Google for Xamarin edit connection string[^]
21 Aug 2023 by headshot9x
I have a string content with some keywords and values. I want to get value follow the keyword. string _str = "{ Text = Banana, Value = 81 }"; //string _strText = "Banana"; //string _strValue = "81"; How...
16 Aug 2023 by George Swan
Here is a simplistic approach static void Main(string[] args) { string str = "{ Text = Banana, Value = 81,Text = Apple, Value = 11,Text = Orange, Value = 21 }"; //Convert to KeyValue pairs eg. Banana:81 ...
14 Aug 2023 by PIEBALDconsult
Here's a simple lookup table class which might be instructive: public sealed partial class LookupTable : System.IDisposable { private static readonly System.Text.RegularExpressions.Regex reg ; static LookupTable ( ...
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...
11 Aug 2023 by Sharyar Javaid
As we all know, Java will not create a new string constant if it already exists in the String Constants Pool. But by that logic, shouldn't s1==s5 and others be true? None of the strings I created used the "new" keyword. What I have tried: ...
5 Aug 2023 by headshot9x
Hi, I have a string with some keyword and values follow. I want to get value after keyword using Regex. For example in this case. I want to get values of class and student. KEYSTRING ...
5 Aug 2023 by headshot9x
Oh, After look at some idea from OriginalGriff. I try spend more time to debug and get like this. Demo link . By the way, all option probably working fine. var _matchClassID = Regex.Match(input.Replace("\r\n", ""), @"\
5 Aug 2023 by OriginalGriff
Try this: string regex = "(\\.*?\"(?.*?)\").*?(\\.*?\"(?.*?)\")"; string input = "KEYSTRING\r\n\r\n \r\n ...
2 Aug 2023 by OriginalGriff
No, because String s1 = "mynameisbond"; uses a single string literal and String s2 = "myname" + "isbond"; uses two that can be combined at compile time into a single literal. But s5, s6, and s7 all get assigned at run time, not compile - so...
7 Jul 2023 by Member 13865334
I have same problem. I install my app in my laptop customer. remote. I have success when install at his staff laptop. but, failed when install at him. the message is: provider not found. my suggest is: 1. windows 11. 2. office 2019. last,...
7 Jul 2023 by QuickBooksDev
We have an existing VB.Net 2017 app that has been running for years on Windows 7. It's using an access database. The system was updated to Windows 10 and access to 2019. If fails on both a 32 bit and 64 bit office of access 2016 and 2019. Error 3706 Provider cannot be found. It may not be...
6 Jul 2023 by bjwaldo
The issue I am having is I get an error "Cannot implicitly convert type System.Environment.SpecialFolder to String". Everything is working great except for btn4 where the error is. Line 61 is the issue " if (windir = folderselect.RootFolder) "...
6 Jul 2023 by Tim the Gamer
There is a method built into the Environment class that takes a special folder enum and returns the full path to that folder. The method is called GetFolderPath. You can use it in your code like. var path =...
5 Jul 2023 by bjwaldo
Ha... I figured it myself.. Just had to go about it a bit differently. private void btn4_Click(object sender, RoutedEventArgs e) { FolderBrowserDialog folderselect = new FolderBrowserDialog(); if...
15 May 2023 by D T 2023
function bs(str){ //storage for new string let newStr = ''; //storage for character codes let arr = []; //loop to cycle through each letter in the string then return it into the array for(let i = 0; i
15 May 2023 by OriginalGriff
Bear in mind that characters sets are reasonable sensible: 'a' is less than 'b', which is less that 'c', and so on up to 'z'. And the same applies for the uppercase letters as well: 'A'
12 Apr 2023 by Member 14711713
"The best time to start is now. Some time gen-\r\n erally means no time. You can put away as much as I put away, if you try.”\r\n “ All right, I’ll do it—next week.”\r\n “ No, this week,” and Dale smiled good-hu-\r\n moredly.\r\n “Gracious, Dale!...
12 Apr 2023 by OriginalGriff
You could just use string.Replace: string str = "\"The best time to start is now. Some time gen-\r\n" +"erally means no time. You can put away as much as I put away, if you try.\"\r\n" +"\" All right, I’ll do...
12 Apr 2023 by Richard MacCutchan
Use the String.IndexOf Method (System) | Microsoft Learn[^], which allows you to specify the starting position to seach from. You could also use String.Split Method (System) | Microsoft Learn[^] to separate into an array of strings delineated by...
11 Apr 2023 by Richard MacCutchan
NB As mentioned by Richard Deeming below, this is only valid with .NET Core. Most of those extra quote characters are unnecessary. Try this: Dim myproc As New Process Dim start As New myproc.StartInfo start.FileName =...
10 Apr 2023 by Michael.Scheytt
Hello, I have a problem that I can't get any further. Even after researching numerous similar cases, I have not been able to find a solution to my problem, hence the question. It's about the topic 'String within String' or quotation marks within...
9 Apr 2023 by OriginalGriff
To duplicate your original command is simple: Dim cmdApp As String = """C:\Windows\SysWOW64\wscript.exe""" Dim cmdPar As String = """C:\Temp\AnyProcess.vbs"" ""Cmd1Par1=AnyVal1 Cmd1Par2=AnyVal2 Cmd1Par3=AnyVal3 Cmd1Par4=AnyVal4"" ""Cmd2Par1...
1 Apr 2023 by Shubham Guha_1007_IMCA1
I am getting same char output multiple times JAVA input - Shubham output - hh I want my output - only - h Here is my code - What I have tried: Scanner sc = new Scanner(System.in); System.out.println("Enter the string ??"); String...
1 Apr 2023 by OriginalGriff
Consider using else if instead of if: I'd simplify that code: Create an array of 26 integers, preset it to all zeros - call it letterCounts Loop through your input string once, for each character, if it's between 'a' and 'z' inclusive, increment...
13 Mar 2023 by Member 12617947
I have a string whose part is always changing, and I want to remove that part from the string like this: Our society, 01:12:15:14 the whole country Our society, the whole country This format should be removed from the string: 01:12:15:14 This...
13 Mar 2023 by OriginalGriff
Use a Regex: Imports System.Text.RegularExpressions ' Regular expression built for Visual Basic on: Tue, Mar 14, 2023, 07:29:32 AM ' Using Expresso Version: 3.0.4750, http://www.ultrapico.com ' ' A description of the regular expression: ' ...
13 Mar 2023 by Graeme_Grant
one way of doing it: Dim message = "Our society, 01:12:15:14 the whole country" Dim result(message.Length) As Char Dim position As Integer = 0 For i As Integer = 0 To message.Length - 1 If "1234567890:".Contains(message(i)) Then ...
10 Feb 2023 by Richard MacCutchan
See Built-in Types — Python 3.10.10 documentation[^] for information on using and accessing strings.
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.
10 Feb 2023 by OriginalGriff
Start be reading the assignment carefully - it may be different from the "summary" you gave us. You need to find all the times that a string occurs inside another. So if you are looking for all occurrences of "hello" in "hello Mike, hello Jane,...
30 Jan 2023 by merano99
As Patrice already said, hardly anyone here will write a ready-made solution without you uploading a source code proposal. My suggestion for the solution would be first to create a lookup table in which all necessary changes are entered. If...
29 Jan 2023 by Simon tIV
Question There are 2 strings, str1 and str2. An operation is defined by replacing all letter α in str1 with a letter β. You can choose α and β. Find the minimum number of 'operations' in order to change str1 to str2. Samples abc to abc: 0...
18 Dec 2022 by OriginalGriff
Here's how I do it: Convert Image to byte[] array:MemoryStream ms = new MemoryStream(); imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp); Byte[] bytes = ms.ToArray(); Convert byte[] array to Image: MemoryStream ms = new...
18 Dec 2022 by Member 14623639
I have a byte[] with image information stored. When I convert the byte[] to image it works but if I try convert byte[] to string and again string to byte[] and use that converted byte[] in ImageConverter it won't work What I have tried: Code: ...
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
13 Nov 2022 by OriginalGriff
"a" is not a number! Try this: a = 95 print(type(a)) a = str("a") print(type(a)) a = str("123") print(type(a)) a = int(a) print(type(a))
9 Nov 2022 by faizy001
hi friends i have this string format "PO-000074/22,PO-000075/22" and i want to convert into this format ['PO-000074/22','PO-000075/22'] how i can solve this problem using jquery What I have tried: i have tried using sub string but i want...
9 Nov 2022 by Richard Deeming
You don't need jQuery - just use the String.prototype.split[^] method. const input = "PO-000074/22,PO-000075/22"; const output = input.split(","); console.log("Result", output);
6 Nov 2022 by merano99
As Richard has already correctly pointed out, this line does not work: gets(category); Here you want to read in several lines. But the command obviously always overwrites the same place, and one that is not intended for that. The gets()...
6 Nov 2022 by Sharyar Javaid
#include #include int main() { int i, types; i=0; printf("how many types/categories of meds you want?\n"); scanf(" %d", &types); printf(" %d", types); char * category[types]; printf("\nPlease...
3 Nov 2022 by Richard MacCutchan
You have two problems: 1 the use of scanf to read values will leave a line end in the input buffer, which causes the next input command to read the wrong data. You need to clear the buffer after the call to scanf: char dummy[4]; gets(dummy); ...
3 Nov 2022 by CPallini
Try #include #include #include #define CHARS 30 int main() { int c, categories; printf("how many types/categories of meds you want?\n"); scanf(" %d", &categories); printf(" %d", categories); char *...
3 Nov 2022 by CHill60
I couldn't get this to work at all using gets - in fact I got a compiler warning telling me not to use it. However, the syntax for gets is char *gets(char *str) and you are passing it a char **str Try replacing gets(category); with scanf("%s",...
22 Oct 2022 by Parth Vijay
The question is first take the number of test cases and take input that no of times from the user.. the input is contains 3 integer value (no of friends, rate of each burger, and the money in hand) if the person have the right amount of money in...
22 Oct 2022 by Richard MacCutchan
Try this: int testCases; cin >> testCases; for (int i = 0; i > friends; cin >> rate; cin >> money; // perform calculations here }
11 Oct 2022 by Maciej Los
Sorry, but your question is not clear... Seems you want to find a substring within a title... Regex is not for such of requirements. If you want to get a text within a "group-title=", try this: .group-title=\"(.*?)\" Example: regex101: build,...
10 Oct 2022 by Jake-J
Hi there, I'm new to regular expression and I'm trying to learn it. I have a string like this: #EXTINF:-1, tvg-name="THE NAME" tvg-logo="THE LOGO" group-title="THE TITLE",THE ITEM https://www.SampleSite.com I'm going to check if THE TITLE part...
9 Oct 2022 by Jake-J
Hi there, I have an M3U file and it's usually formatted likes this: #EXTM3U #EXTINF:-1, tvg-name="NAME 1" tvg-logo="LOGO" group-title="TITLE 1",ITEM 1 https://www.SampleSite1.com #EXTINF:-1, tvg-name="NAME 2" tvg-logo="LOGO"...
9 Oct 2022 by Dario Picca
I prefer use LINQ for this var objects = myString.Split(',') .Where(x => !string.IsNullOrEmpty(x)) .ToList();
9 Oct 2022 by OriginalGriff
A newline isn't an empty entry because any empty entry is an empty string: one which contains no characters at all. Newline is a character (or two characters on some systems) so it doesn't get removed. Try adding a newline to your separating...
2 Oct 2022 by CPallini
If you just need to 'abbreviate' the input, then you might do it in place, without messing with pointers. #include #include int main() { int i = 0; char line[50]; fgets(line, sizeof(line), stdin); while (line[i])...
2 Oct 2022 by merano99
If the warnings were switched on with your compiler it would have warned you, that the uninitialized local variables "p" and "q" are used. if (q[k] >= 'a' && q[k]
2 Oct 2022 by Parth Vijay
Hey, I 'am a beginner in C language. problem 1: Have i used pointer p and q properly. problem 2: After taking the input health care the program just crashes. health care after this the program crashes. What I have tried: #include ...
2 Oct 2022 by OriginalGriff
You don't allocate any memory to q or p, nor do you assign them any value. So when you try to access them, what you get is just a memory access at random and your app crashes. BUt you should have spotted that for yourself, and you would have if...
2 Oct 2022 by merano99
Numbers like 10 and 15 are better with names, it makes it easier to read. That memory must be allocated for all strings has already been written. You could get the memory with only one malloc at a time and then allocate only pointers. It would be...
2 Oct 2022 by Parth Vijay
Problem 1: I'am not sure if i have used array of character pointers correctly or not. Problem 2: The use of scanf()? Can we input a string in string[i](which is actually a element on array of character pointer)?(You can ignore the use of...
2 Oct 2022 by Richard MacCutchan
You cannot read (or copy) text data into arrays that do not exist. Your allocation of an array of pointers is correct, but you then need to initialise each pointer, so that it actually points to some memory space, something like: for (i = 0;...
27 Sep 2022 by Michael Sydney Balloni
Different languages and approaches are evaluated for a file and string processing benchmark
28 Aug 2022 by Apoorva 2022
Following is a date validation program. I'm trying to print the date in words. I got the 'str' object is not callable' error at this line --> av=date(day, month, year).strftime('%d %B %Y') But I did convert day, month, & year into integers...
28 Aug 2022 by Richard MacCutchan
I gave you the answer to this two days ago at Python date validation program - output query[^].
28 Aug 2022 by OriginalGriff
Look at the error message: 'str' object is not callable' error at this line --> av=date(day, month, year).strftime('%d %B %Y') You are calling two functions here: date and strftime so one of those is wrong. Break the line in two and see if that...
20 Aug 2022 by Brian C Hart
Example of how to use the caret (^) in Regexes that have specific matching requirements
21 Jul 2022 by salam_verdim_alana_panyatkasi_olana
Hi there, I have file name which is called for example Quote: 4jl5kljza8100pFileName.pdf and I want to remove until F, but I want to do this by character for example fileName.removeBySpesificCharacter("F"); and I want to get back the result...
21 Jul 2022 by Patrice T
Quote: Is there any method in java cut string value by spesific value? Did you tried to use RegEx ? This RegEx "[A-Z].+" match from first uppercase til the end. Just a few interesting links to help building and debugging RegEx. Here is a link...
21 Jul 2022 by CPallini
[fixed, thanks to zemiak123] You may use the String.indexOf[^] method. Try static String untilChar(String strIn, int chr) { int index = strIn.indexOf(chr); if ( index != -1 ) { strIn = strIn.substring(index); } ...
21 Jul 2022 by dejf111
Hi, I am trying to create a CIMTextSymbol that I could write my string into. Below in the code I have created a generic CIMTextSymbol , but I would like to write some text with it. What I have tried: private static Task...
21 Jul 2022 by Richard MacCutchan
See the sample code at CIMTextSymbol Class—ArcGIS Pro[^].
30 Jun 2022 by Member 15078716
Since you are using Code::Blocks (undisclosed version), and since you are using Microsoft Windows (undisclosed version), and since you are using MinGW (undisclosed version) with probably GCC (undisclosed version), which all that is OK, then...
30 Jun 2022 by nxc121
HiI am really having trouble dealing with adding unicode support to my code, i have perfectly working ASCII code but then with entry of some chinese and korean charectors making it break. I tried on web to search for sample code or guide but there is no enough proper info so looking for...
29 Jun 2022 by Member 12617947
I have a text box and there are some string in it that could be anything and I need to split that string into every 38 characters But the code I use does not work properly Because sometimes after 38 characters it is possible to create the correct...
29 Jun 2022 by OriginalGriff
There is no "standard method" that will do that for you, but it's not too complex. Start by finding out what the 38th character is: letter or punctuation. If it's a letter, look back to find the first punctuation character and split the string...
27 Jun 2022 by Sreenath Sreenath
\\ #include #include int main() { int num=10; int *ptr; *ptr=# printf("%d",*ptr); } \\ What I have tried: if i declare *ptr=&num it is showing an error (INT FROM INT MAKES INTEGER FROM POINTER WITHOUT A CAST) if i declare int...
27 Jun 2022 by OriginalGriff
Pointers are a little complicated. When you write int num = 10; you are declaring a variable that holds an integer, and assigning it a value: 10 You can do maths with that, and print it if you want: int num = 10; num = num + 100; printf("num =...
27 Jun 2022 by steveb
*ptr is dereferencing. Dereferencing is used to access or manipulate data contained in memory location pointed to by a pointer. *(asterisk) is used with pointer variable when dereferencing the pointer variable, it refers to variable being...
24 Jun 2022 by Sreenath Sreenath
1)how (s[i]!=0) evaluates? 2)how does *(s+i) works? 3) how does i[s] works? please help me with these douts What I have tried: #include #include int main() { char s[]="peak"; int i=0; while(s[i]!=0) { ...
24 Jun 2022 by OriginalGriff
C doesn't have any concept of strings past "string literal": a sequence of characters enclosed in double quotes. So when you are traversing a char array, you need to know either how long the string is, or look for a string terminator character....
6 Jun 2022 by Member 11134333
I have 2 strings Str1 and Str2 When I am comparing these two strings. This If condition returning false, why it is returning false as substring in Str2 is present in Str1. What I have tried: Str1="ABC Properitory Limited"; Str2="(Properitory...
6 Jun 2022 by Tony Hill
If as Rick suggests you are confusing it with a Regex comparison you would have to do something like this to test if the pattern exists in the testdata. string testdata = "ABC Properitory Limited XYZ"; string pattern =...
6 Jun 2022 by RickZeeland
You probably are confused with Regex functionality, see: C# Regex.Match Examples[^] .Contains() just searches for a string, see: C# Contains String Method[^]
22 May 2022 by Phoenix Liveon
A quick quest: We want the result looks like this; from aaa---bbb-ccc into aaa.bbb.ccc What I have tried: def objective = "aaa---bbb-ccc" objective.replace(/.*[-]+.*/, '.') How do we create a proper pattern of Regular expression in Groovy?
15 Apr 2022 by Phoenix Liveon
I found some answer and this is what its looks like we substitute method "replace" with "replaceALL"; def objective = "aaa---bbb-c" println( objective.replaceAll(/[-]+/, '.') )
15 Apr 2022 by OriginalGriff
That's because you don't use the "non-hyphen" data in your replacement. Try this: (.*?)-+(.+?)-(.*) And this replacement string: $1.$2.$3
15 Apr 2022 by Patrice T
Did you tried this ? def objective = "aaa---bbb-ccc" objective.replace(/[-]+/, '.') Just a few interesting links to help building and debugging RegEx. Here is a link to RegEx documentation: perlre - perldoc.perl.org[^] Here is links to tools...
27 Mar 2022 by SHEIKH AHNAF AZMAIN
The objective is to make a linked-list tree of groups of students of a subject. the tree should work with the subject being the root, the group leaders being the first level of leaves, and the members of the group branching from their respective...
27 Mar 2022 by CPallini
I think you should revise your data structure. I propose you a skeleton (you might complete it adding dynamic memory allocation and all the details) #include #include #include #define SIZE 100 struct MemberNode {...
25 Mar 2022 by User 15541525
Hello! I'm kinda new to programming so here's my problem. How can I reverse a String and then at the same time make the last letter deleted using a loop until all what's left is a single letter. For example: User inputs "programming" The...