Most voted "string" questions
A string is a sequence of zero or more characters. It is commonly used to represent text or a sequence of bytes. When marking a question with this tag, also mark with the programming language to be used and the operation being attempted with the string.
Learn more…1,904 questions
Sort by count of
-
122
votes6
answers17915
viewsHow to make a phonetic algorithm for Brazilian Portuguese?
To facilitate the search for commonly misspelled information, we use phonetic algorithms. A feature that is extremely useful but that is often neglected, especially outside the English language…
-
79
votes8
answers16873
viewsHow to invert a string in Javascript?
How to invert a string in Javascript? For example: Entree: "something here" Exit: "iuqa asioc amugla"
-
71
votes8
answers49747
viewsHow do I remove accents in a string?
I have a string áéíóú That I want to convert to aeiou How do I remove accents? Need to save to database as a URL.
-
59
votes4
answers106387
viewsHow to compare Strings in Java?
The operator == says that strings are different, they store the same literal value, see the example: public class TesteString { public static void main(String[] args) { String str1 = "teste"; String…
-
57
votes5
answers7848
viewsWhat is the difference of string vs string?
I wonder what the real difference is between String (capital letters) and string (s tiny). Apparently the two have the same goals, but which is "best" to use?
-
55
votes2
answers39510
viewsHow to remove accents and other graphic signals from a Java String?
How to remove accents and other graphic signals from a Java String? Ex.: String s = "maçã"; String semAcento = ???; // resultado: "maca"…
-
49
votes4
answers5144
viewsWhat does the "@" sign on C" mean?
I have the following string @"\\servidor01\arquivos". What is the function of @ in front of the string?
-
49
votes1
answer2641
viewsWhat does the symbol "$" mean before a string?
Viewing a code here in Sopt, I noticed the use of the symbol "$" and I was left with doubt about its use. What is the symbol "$" before a string? What good is he? Why use it? Example using static…
-
38
votes4
answers66720
viewsWhat is the correct way to make a regular Javascript substitution for all occurrences found?
What is the correct way to make a regular Javascript substitution for all occurrences found? The way I do these days: var i = 0; while ((i = str.indexOf("_", i)) != -1) { str = str.replace("_", "…
-
32
votes5
answers10820
viewsHow to Reverse a String?
A user will enter a sentence and I must display this inverted sentence in upper case. How can I do this? import javax.swing.JOptionPane; public class ExerLar01 { public static void main(String…
-
31
votes4
answers28968
viewsWhat is the most appropriate way to concatenate strings?
There are different methods for concatenating strings, such as Concatenating with the operator "abc" + str Formatting String.Format("abc{0}", str); Using the Stringbuilder new…
-
31
votes6
answers36799
viewsHow to read a text file in Java?
I have the file called dados.txt and I want to put it on String. For example: String texto = lerArquivo("conteudo.txt"); Question How to write this method lerArquivo()?…
-
30
votes3
answers2867
viewsCapitalizing on C#names
I have in my application given names in capital letters, for example: "JOSÉ DA SILVA". I would like to format as follows: "José da Silva". How to do?
-
29
votes3
answers1131
viewsString and its efficiency
Doubt I would like to know what design patterns or other "nerdy" things have been applied to this class StringBuffer. Why does String create new objects in a concatenation? As far as I know, String…
-
29
votes1
answer1107
viewsWhat is Null Byte Injection? How to avoid it?
What would that be Null Byte Injection? How to avoid it?
-
26
votes2
answers1892
viewsWhat is the difference, in practice, between "" and String.Empty?
No. NET is noticeable in multiple ways to initialize a string with an empty value, called "quotation marks". Is there a right way to do this? And what would be the practical difference between…
-
25
votes3
answers1989
viewsHow do I know if the first digit of a string is a number?
I have a form where I need to validate the taxpayer number. If you start with PT or if it is a number without an acronym I validated by the Portuguese finance algorithm, otherwise I do not validate.…
-
24
votes5
answers20688
viewsHow to verify similarity between strings?
It’s very common to compare strings, which is usually done by comparing equality. However, today I have arisen the need to compare the likeness between two strings, so I can compare how similar they…
-
23
votes5
answers2310
viewsWhy are other encodings used besides UTF-8?
If UTF-8 encoding can represent all Unicode characters, why are there still applications that adopt other encoding standards such as ANSI? It would not be easier to abandon all those that do not…
-
22
votes2
answers2225
viewsCompile string as code
There is how I compile a string within C#? Example: Console.WriteLine(\"Hello World\");. Like a eval javascript? 'Cause I had a project to load a code into a text file or something.…
-
22
votes1
answer1099
viewsWhat is the difference between Integer.valueOf() when using String or int parameters?
Why in the lines below the results of System.out are different? Integer teste = Integer.valueOf("0422"); Resultado: 422 Integer teste = Integer.valueOf(0422); Resultado: 274 If step one int it…
-
22
votes3
answers57329
viewsFormat double with mile and decimal
I have the following value: 43239.110000000001 I used this command: txtSomatorio.Text = String.Format( "{0:#.#,##}", somatorio); I got this: 43239,11 How to do to display like this? 43.239,11…
-
22
votes2
answers19395
viewsWhat’s the difference between varchar and nvarchar?
What’s the difference between using data types varchar and nvarchar? nvarchar exists in every SQL database? Is there any significant difference in performance between the two? There is a criterion…
database sql-server string typing character-encodingasked 7 years, 6 months ago UzumakiArtanis 9,534 -
21
votes2
answers378
viewsPerformance in creating strings in Java
What is the best way to create strings in Java to get better performance? Here are two examples of creating strings in Java: Ex. 1: String str = "string"; Ex. 2: String str = new String("string");…
-
20
votes4
answers6604
viewsHow to extract a file extension in Javascript?
There are some cases where I need to capture a file extension (that is, a string with the file address) in order to validate the extension via Javascript. For example of location: var path =…
-
20
votes1
answer422
viewsIs replacing strings with Regex slower than Replace()?
Let’s say I want to do something like this question: How to convert Camelcase to snake_case in C#? You had some answers, but I want to highlight these two. Answer 1 string stringSnake =…
-
19
votes2
answers5046
viewsWhat is the difference between Isnullorempty and Isnullorwhitespace?
Li here that there is no practical difference between String.Empty and "", and then the doubt came to me. What’s the difference between using String.IsNullOrEmpty(String) and…
-
19
votes4
answers1350
viewsHow to pass string by reference?
I passed a string as a parameter. As far as I know it is passed by reference, so if I change anything in it within the method, when it leaves it the value will continue to change. I took the test…
-
18
votes7
answers44529
viewsHow to get only the numbers of a string in Javascript?
I wonder if there are functions that return only the numeric values of a string, if there is not, what is the simplest and efficient way to implement? Example: apenasNumeros("5tr1ng"); Upshot: 51…
-
18
votes3
answers11309
viewsHow to delete duplicate spaces in a string?
I have the following string: var str = "00000.00000 111111111.111111111111 33333333" I need to remove the extra spaces for it to look like this (only with 1 space): var str = "00000.00000…
-
18
votes2
answers837
viewsWhat is the equivalent of the equalsIgnoreCase() in Kotlin?
What is the equivalent of the method String.equalsIgnoreCase() of Java in Kotlin?
-
18
votes5
answers1237
viewsWhat is the difference between substr and substring?
I want to know the difference between alert("abc".substr(0,2)); and alert("abc".substring(0,2)); Both appear to produce "ab".
-
17
votes3
answers72494
viewsHow can I check if one string contains another in Javascript?
I would like to check if one string contains another, as if it were a method String.contains() but apparently there is no method to do this. Does anyone know a similar method that does the same…
-
17
votes4
answers8554
viewsHow do LTRIM() and RTRIM() in Java?
I need to process some strings in Java. I know the method exists trim(), but I need a Left Trim and of a Right Trim. How do I do this? For now I’m walking the string with a loop and removing all…
-
17
votes4
answers1239
viewsFormat city names and ignore words like "do", "dos", "das", "da", etc
I’m working with Webservice whose city names are all out of shape and I’d like to create a function to treat the names evenly. An example is this: CHICKEN HARBOR I’d like to keep it that way: Porto…
-
17
votes1
answer1949
viewsWhenever I am going to scan a string in C I must use "strlen()", right?
It is common to see in C execs that people need to analyze and/or manipulate the content of a string, then we need to make sure that it will not exceed its limit. It is very common to make a for…
-
16
votes5
answers2736
viewsTest whether all characters of the first string also appear in the second
I’m trying to do that function with the help of the functions strcmp() and strncmp() and I’m not having much success. Let’s say I have the string char s[] = "abc" and another string char v[] =…
-
16
votes2
answers2766
viewsWhat is a string template (literal string declared with "`" grave accent) for in Javascript?
I was fiddling with the Chrome console these days and then, as my keyboard was disfigured, I accidentally typed the grave accent ` instead of single quotes ' to create a string. The interesting…
-
16
votes11
answers38715
viewsHow to check if the variable string value is number?
I am developing a program where the user type a data, then I have to check if the value is number to proceed with the operation, but if he type a non-numeric value he is alerted about the invalid…
-
15
votes4
answers844
viewsrtrim() to remove "<br>" also removes the letter "r" if it is the last letter in the string
If a string ends with an HTML tag, for example <br> or <hr>, when making use of the PHP function rtrim() to clear said tag, in cases where the letter immediately before is an "r", the…
-
15
votes3
answers17342
viewsHow to use more than one separation character in the split() method?
I’d like to break a String in various substrings, for this I am using the method split(). Turns out, I’m not sure which characters might be in the variable I use. Exemplifying: String words[] =…
-
15
votes1
answer10089
viewsDifference between Integer.valueOf(String) and Integer.parseint(String)
I need to convert a String in int, and I came across these two options, which have an equal result. Is there any difference between them? Is there any rule/convention that says which to use or is…
-
15
votes2
answers5787
viewsCut string when it reaches space
Example: I have a string "João da Maquipe", as I do to cut in space, leaving as a result: "João" or "João". whatever. In PHP I know, but in C# I have no idea.
-
15
votes8
answers5012
viewsPrinting a String until a space is found
I receive a String through an input and enter it into the database. When I list, I only want the person’s first name, that is, until the first space is found. Is there any function that does this?…
-
15
votes3
answers2048
viewsWhat is the function of the toString() method?
What is the function of toString() in Java? Why do we do System.out.println(compObjeto) and in the main() (assuming there is an object for the class comp called compObjeto), he does print of…
-
14
votes3
answers2493
viewsHow to check if a string has only uppercase letters?
How can I check whether all the characters in a string are capital letters? Preferably without the use of regular expressions.
-
14
votes6
answers1877
viewsCode refactoring to convert GPS coordinates into DMS format into an array
The user can enter GPS coordinates in two ways, Decimal Degrees or Degrees, Minutes, Seconds: ┌─────────────────────────────────┬─────────────────────┐ │ DMS (Degrees, Minutes, Seconds) │ DD…
-
14
votes1
answer441
viewsWhat is the purpose of Array and String Dereferencing implemented in PHP 5.5?
In the PHP manual, we can see New Features the functionality of Array and String literal Dereferencing. Example: echo 'string'[2]; // r echo ['stack', 'overflow'][1]; //overflow Thinking in case you…
-
14
votes5
answers42959
viewsFunction equivalent to Trim (function to remove extra spaces at the beginning and end) in Python?
In PHP and Javascript, we have the function trim that serves to trim a string, removing extra spaces at the beginning and end. Thus: $str = ' meu nome é wallace '; var_dump(trim($str)); //…
-
14
votes4
answers486
viewsHow would an algorithm work to prevent attempts to trick word blocks (strings)?
Let’s say I develop an application that allows the creation of arbitrary records (no matter the subject). However, for some reason, I have decided to block the use of the word batata in the title of…