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
-
10
votes3
answers25526
viewsHow to delete a character within a string?
In this code I read two strings and I withdraw from the first all the letters in common with the second string. But how to put a null character in place of this common letter in both strings? My…
-
10
votes2
answers19497
viewsHow to get a snippet of a string?
I have a string like this: ~/Areas/Teste/Views/home/index.cshtml I just need the word that comes right after ~/Areas/, in the case Teste (remembering that this word may vary in size). How do?…
-
10
votes3
answers13854
viewsFill string with zeros on the left
I’m doing a work of Operating Systems and need to turn decimal numbers into binaries. So far so good, because the method below takes an integer and converts to binary. My problem is the following:…
-
10
votes5
answers6566
viewsRemove last comma from an array
In this Code below I have a array that returns a comma to me at the end exe: '98602','98603','98604', How can I remove this comma? if (isset($_POST['checkbox'])) { foreach ($_POST['checkbox'] as…
-
10
votes2
answers1835
viewsWhat is the difference between 'string' and r'string in Python?
I was taking a look at Django’s code, framework in Python, and I came across the following code in the file urls.py. urlpatterns = [ url(r'^articles/2003/$', views.special_case_2003),…
-
10
votes2
answers455
viewsString Interpolation performs better than string. Format?
I use Resharper and a few days ago I started using some C# 6 features. In various parts of the code use string.Format() and I realized that Resharper suggests that these snippets be replaced by…
c# .net string string-concatenation string-interpolationasked 9 years, 1 month ago Jéf Bueno 67,331 -
10
votes9
answers17879
viewsHow to identify if a string is a palindrome?
A palindrome is a word or phrase that has the property that can be read from right to left and from left to right. For example, the strings "aaaaa", "1221", "bbaabb" are palindromes, however the…
-
10
votes4
answers1970
viewsHow to abbreviate words in PHP?
I have common information like people names and addresses, and I need it to contain at most 30 characters without cutting words. Example: 'Avenida Natalino João Brescansin' => 'Av. Natalino J.…
-
10
votes2
answers6643
viewsWhy is my function concatenating instead of summing the numbers?
I am learning Javascript and I am breaking my head with this code that I created. Why is my function concatenating instead of summing the numbers I store in the variables? <!DOCTYPE html>…
-
10
votes3
answers1653
viewsPicking up part of the phone
In the registration, the user registers his phone and this field is masked (99)99999-9999 and this is saved in the BD. if I want to use only the DDD of this, and the separate numbers, how should I…
-
10
votes1
answer227
viewsDifference between printf and format
Is there any difference between using the printf and the format? Example 01: float nota = 5.3f System.out.printf ("Sua nota: %.2f", nota) Example 02: float nota = 5.3f System.out.format ("Sua nota:…
-
10
votes2
answers1420
viewsHow to split a String that contains white spaces at the beginning?
For the problem in question, I need to remove all the special characters and spaces and count the new possible outputs. My intention is to separate the string with the method split(). For this,…
-
10
votes2
answers111
viewsWhat is the name of this structure in Python?
In the following code: first_part = 46 last_part = 57 guess = f'{first_part}{last_part}'.encode() print(guess) print(type(guess)) But I didn’t understand the code: guess =…
-
10
votes5
answers9012
viewsHow to replace more than one character in the replace method in Python 3?
I have the text and need to remove all punctuation marks using just one method replace(), without using tie as well. My initial idea would be to use texto.replace('.', ''), this for each type of…
-
10
votes2
answers5589
viewsWhy should we use PHP_EOL?
I’ve been informed that PHP_EOL sets the end of the line, ok. But why should I write. echo 'a'.'<br>'.PHP_EOL; echo 'b'; If the echo 'a'.'<br>'; echo 'b'; It has the same effect, what…
-
10
votes2
answers230
viewsWhat does the / +/g parameter mean in the . split() method?
Can anyone explain to me what the parameter means / +/g within a method .split()? var message = "-lucas o p i "; var args = message.slice(1).trim().split(/ +/g); var comando =…
-
9
votes5
answers7529
viewsHow to search recursively using grep
How to search for a given word recursively in all files in the current directory and its subdirectories? I tried to travel with: find . | grep "palavra"
-
9
votes2
answers7414
viewsManipulating String in Java
I have a text inside a String. I will go through this String. Going through it I need to pick up every word it contains. I thought I’d use string.split(" "); but I need to treat "." ;" "," ":" "!"…
-
9
votes2
answers717
viewsReceive variable value without passing parameter
I have the following method: private string toCamelCase(string text) { text = string.Format("{0}{1}",text.Substring(0, 1).ToLower(),text.Substring(1)); return text; } To use it I need to call it…
-
9
votes1
answer1038
viewsIs there a data structure like an associative array in Java?
Well, I’m wanting to name an Array of Strings in Java, but I wanted it to be, for example: String[] symbols; And could be declared so: symbols["name"] = "Tiago"; I know there’s no such Array, but…
-
9
votes1
answer8805
viewsSeparate string by number of characters
I’m developing a component to read the file sent by Dataprev with the list of monthly obituaries. This file is a TXT and every 210 characters is a different person. The documentation can be seen in…
-
9
votes6
answers8412
viewsFunction that enumerates letters of the alphabet
How to convert alphabet letters into one array of numbers according to its sequence? The array should start from paragraph 1, not zero. So the letter A valeria 1, B valeria 2, C valeria 3, and so…
-
9
votes4
answers8429
viewsHow to use template string in Javascript?
I’m having trouble making a Javascript function that I pass a string and an object and it fills this string with the attributes of that object, for example: var user = { nome: "danilo", idade: 29 };…
-
9
votes1
answer197
viewsif with a Matches or multiple comparisons?
Whereas I have a variable of the type String tipoResidencia that will never be null, and that I need to run a test, the default solution is this: if (tipoResidencia.equals("CASA") ||…
-
9
votes1
answer2403
viewsWhat is Cultureinfo.Invariantculture?
I installed Resharper and on that stretch x.Id.ToString() he suggests changing to x.Id.ToString(CultureInfo.InvariantCulture). What is CultureInfo.InvariantCulture and why that way is better?…
-
9
votes4
answers301
viewsHow to find hashtags in a string and store them in an array?
I have a content posting system on a particular social network of our company. When the user type the text with hashtags, I need to detect all of them and store them in an array. Example: Hi, I’m…
-
9
votes1
answer1033
viewsGet index back to front
Imagine I have the following string: string texto = "Stackoverflow em Português"; If I want to know the index of the first space, just: int index = texto.IndexOf(" "); But in this case I have two…
-
9
votes3
answers156
viewsRegular expression to reorder string
I have the result of a query with several joins, and in a row I have the concatenation of 2 groups. The line returns me a string as: 1,4|a1,b4. What I need is to regroup ID and Valor as follows:…
-
9
votes1
answer1019
viewsEncrypt a phrase/word by reversing and switching vowels with the following vowels
I was given an exercise in which I have to write a program that reads a word in the interval [1-20] and encrypt this word using the steps: reverse the word where there is a vowel, replace with the…
-
9
votes4
answers48238
viewsHow to convert a String to Int in Javascript?
HTML5: <!DOCTYPE html> <html> <head> <title>JSTest</title> <meta charset="UTF-8"> <script src="JSource.js"></script> </head> <body>…
-
9
votes4
answers1246
viewsIdentify if all characters are equal
I have the following code that works perfectly. In it I possess a string and check whether all of its characters are equal or not: var numbers = '1111121111', firstNumber = numbers.substr(0,1),…
-
9
votes6
answers300
viewsHow do I transform an array that is in a string for javascript array?
I have a string representing an array as follows: var = "['aaaaa', 'bbbbb', 'ccccc', 'ddddd']"; Wish I could transform this array that is in the string into an Array to perform manipulations. var =…
-
9
votes3
answers40567
viewsWhat is the correct way to concatenate strings in Javascript?
I started learning Python and was told that I shouldn’t concatenate the strings with , but use the method .format(). And in Javascript it is correct to use + or , to concatenate the strings or there…
-
9
votes1
answer690
viewsWhy is it better to use char[] than String for passwords?
Using Swing, the method getPassword() of JPasswordField returns a character array char[] instead of returning a String like the getText() (which by the way is discontinued). I should not use String…
-
9
votes1
answer207
viewsWhat is the difference between String name = "test" and String S4 = new String("Peter");
What’s the difference of assigning a value to a variable by creating an object and assigning Unboxing at a direct value? String s4 = new String("nome"); String nome = "nome";…
-
9
votes2
answers4659
viewsWhat is the flush parameter of the print function?
I realized that there is the parameter flush in function print python: print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) I know that: The parameter *objects sets the list of values to…
-
9
votes3
answers619
viewsWhat is String.raw for in Javascript?
Well, that’s the question. I would like to know what the method is for String.raw in Javascript. I saw something in the documentation of MDN, but I did not understand very well the use Has something…
-
9
votes5
answers1894
viewsTest for string fill
When reading a post on good programming practices, more related to validating the filling of strings, I came across the following: Very slow check: string ret = String.Empty; if…
-
9
votes2
answers643
viewsHow does the int function handle the n character?
I created a list: usuarios = ['123\n','123\n4'] I tried to turn the index 0 into integer using the int() int(usuarios[0]) Upshot: 123 But when I tried to do the same with index 1: int(usuarios[1])…
-
9
votes3
answers2052
viewsConvert a comma-separated string to a multidimensional array
I have a string thus ... var listAdd = "1789, 3, 8 , 1788, 3, 8, 1790, 3, 9" How do I convert into a array as below? [1789,3,8], [1788,3,8], [1790,3,9] The code I’m trying isn’t working: var…
-
9
votes4
answers150
viewsWhat regular expression to use to replace symbols in a string?
I got a string, just like "1x2,4÷4" and I want to replace the x for *; to , for . and the ÷ for / using the replace javascript. Which regular expression I would need to use to make this replacement?…
-
8
votes3
answers1054
viewsRegex to select specific stretch
I need to identify within contracts the name information, CPF and address. The landlord’s line is as follows: LESSOR: Jose Reinaldo Lellis de Andrade RENTAL COMPANY: Isabel Cristina de Rezende Leme…
-
8
votes4
answers6417
viewsHow to split a string into C++?
I received this simple (I really thought it was!) challenge of creating a "tokenizer". I had to split the string " O rato roeu a roupa do rei de roma " into spaces. Then, after a long time, I…
-
8
votes2
answers9026
viewsAlgorithm in C to convert Arabic number to Roman number
How to make this conversion? It doesn’t need to be the algorithm ready, wanted a help at least in logic.
-
8
votes4
answers6348
viewsDetecting Line Break
I have the following function: if (str.match(/\d\d\d\d\d\.\d\d\d\d\d/)) { var codigo_velho = str.match(/\d\d\d\d\d\.\d\d\d\d\d\/); result = "1"; } How to change this function so it detects line…
-
8
votes2
answers478
viewsHow do I get a loose number in my HTML?
Consider the following code: <span class="test"><span style="color:green">Teste</span>:</span> Text<br><br> <span class="test"><span…
-
8
votes3
answers644
viewsInsert string data into a table
I have a text file that I read and adjusted in a string texto so that it would stay that way: {nome="Cassio",sexo="M",idade=19} {nome="Paula",sexo="F",idade=20} And I used the following code to add…
-
8
votes2
answers39212
viewsReplace in SQL - Character to keep a piece of text
I need to modify a part in the text of a table. The records of an email are [email protected] and I need to change everyone to jf.jus.br. Only the first part of the email doesn’t change (the xxx). I can…
-
8
votes4
answers2315
viewsHow to format a value in Javascript?
What is the simplest way to format the value 1234213412341 for 1234.2134.1234-1 using Javascript? <script> function formatar_valor(strvalor){ var formatado; // formata return formatado }…
-
8
votes1
answer9291
viewsExecute cmd commands from Java
I wonder how I do to execute cmd commands in java. Well, I did that: import java.io.*; public class Commands { static final Runtime run = Runtime.getRuntime(); static Process pro; static…