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
-
7
votes3
answers312
viewsTransform a string into multiple substrings whose contents are between apostrophes
I am creating a program in C# that reads a text file and one of the lines of that file has the following format: 'Column 1' 'Column 2' 'Column 3' I want to turn that line into one array of strings…
-
7
votes4
answers3293
viewsSeparate String Number Letters
I need to separate the characters of a string into numbers and letters. Ex.: Entree: "A1B2C3D2Z9" Exit: List<Character> numeros = { '1','2', '3' } List<Character> letras = { 'A', 'B',…
-
7
votes2
answers1882
viewsHow to convert a text to number?
How should I convert a text that I know is an entire number coming externally? It would be something like a ToInt() or something like that.
-
7
votes1
answer17403
viewsWhat is the best way to concatenate strings in Python?
I know I can concatenate strings with +=, +, join() and append(). They all give me the same result when I concatenate two strings. What is the best way to concatenate Python strings? What is the…
-
7
votes3
answers160
viewsCheck if you have more than one character in a String
How can I check how many "@" you have in a string? example: "@Teste @Teste" has 2 @, how can I do this java check?
-
7
votes2
answers10403
viewsHow to separate a string into pieces?
In other languages there is split, explode or something like that string in pieces according to some separator. There is something ready in C or I have to do in hand?…
-
7
votes1
answer107
viewsCompare Strings by format not by value
I have a shape of a String, for example: xxxx-xxxx-xxx But instead of the x can enter several letters or numbers, example: A216-0450-013 X2LP-1018-589 Y585-0000-047 What I need to do is compare to…
-
7
votes1
answer7242
viewsString matrix
How a matrix of strings? I tried it in several ways and still did not succeed, I thought it would work but it did not work. #include <stdio.h> #include <stdlib.h> int main(void){ char…
-
7
votes4
answers7124
viewsAccept only numerics in input
nota = -1 while nota < 0 or nota > 10: nota = int(input("Informe a nota entre 0 e 10: ")) if nota < 0 or nota > 10: print("Valor inválido") I need to include this validation code to, if…
-
7
votes2
answers1249
viewsReturning function string directly and with array
What works: void *teste(); int main () { printf("\nRESULTADO: %s\n", teste()); return 0; } void *teste(){ return "Ponteiro"; } What goes wrong: void *teste(); int main () { printf("\nRESULTADO:…
-
7
votes2
answers957
viewsWhat is the way to truncate a string in Csharp?
I have a scenario where I have set the maximum size of a field. I want to cut that amount to the limit. I am doing this through the Substring, but returns an error when I have a character of smaller…
-
7
votes3
answers4835
viewsIt is possible to concatenate numbers of type int
For example 10 and 12, concatenated would be 1012, this without being string, it would have to be the whole kind, you can do it?
-
7
votes2
answers1093
viewsReplace empty or blank letter, something like Replace("letters","")
There is a field in the database A1_ZTEL he is varchar(15). This way each user entered record of all forms, with bar, point, comma and letter. Now I need to ride a form and read this field from…
-
7
votes2
answers4189
viewsHow to generate the alphabet with white space between letters?
In Haskell I can generate the alphabet as follows: alfabeto = ['a'..'z'] To display it is enough: alfabeto "abcdefghijklmnopqrstuvwxyz" However, I would like to know how I can put a space between…
-
7
votes3
answers816
viewsRemove spaces from a string from the second occurrence
Currently I am removing spaces using a simple replace() and adding a space I must preserve between the third and fourth character using substr() let str = 'abc defghijk lmnop qrstuv wx y z' str =…
-
7
votes3
answers4852
viewsHow to remove accents with regular expressions in Python?
I am developing a regular expression to try to replace accents and characters with normal characters Example: á = a ç = c é = e But mine regex is just eliminating some hint? import re string_velha =…
-
7
votes2
answers339
viewsWhy does String hashcode() in Java use 31 as a multiplier?
In Java, the code hash for an object String is computed as s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] using integer arithmetic, where s[i] is the i-nth character of the string, n is the string…
-
7
votes7
answers1103
viewsRemove part of string until nth occurrence of a character
I have a string that always returns in any of these formats: "0001>0002>0003>0004>0005" "abcdef>ghi>jkl>mnopqr>stuvx" Always has the character > dividing something.…
-
7
votes2
answers504
viewsReplace ")" by space using str_replace_all() in R
I got the following data.frame: cadastros <- data.frame( email = c('[email protected]', '[email protected]', '[email protected]', '[email protected]'), telefone = c('(61)99831-9482',…
-
7
votes2
answers173
viewsSearch range of numbers (string type) with Expression Lambda?
I have this data model and I don’t know how to do the instruction lambda: public class CidadeAbrangencia { [Key] public int CidadeAbrangencia_Id { get; set; } public string CEPInicial { get; set; }…
-
7
votes2
answers94
viewsProblem when typing str in Python
I wrote that code: while True: try: n1 = int(input('Digite o número 1/5: ')) except ValueError as e: print("Digite um número:",) if ValueError: n1 = int(input('Digite o número 1/5: ')) try: n2 =…
-
7
votes1
answer115
viewsDoubt strings Pyhton
I created an algorithm that encrypts words and messages. To work it needs a simple numeric key, such as 9, 4, 2, where the first letter will be displaced 9 positions, the second 4, etc. All running…
-
7
votes1
answer94
viewsWhat are the differences between ways of manipulating huge strings with Python?
When it is necessary to work with strings very large it is normal to see approaches that seek to optimize the process in some way. Of the approaches I have seen are using: io.StringIO or io.BytesIO…
-
7
votes2
answers347
viewsDoubt about the use of the Join method
I’m doing a Javascript course and I came up with a question in one of the exercises. Below is the exercise: Given the following object array: var usuarios = [ { nome: 'Diego', habilidades:…
-
7
votes1
answer198
viewsHow to put emoji in a string?
I know that in a string I can put any characters you want, ex: string = "qualquer coisa! @#$%ª太陽" But what if I want to put one emoji in a string, how do I? Has any specific way? Can I put it right…
-
7
votes2
answers141
viewsHow to Split by Capital Letters and Numbers at the same time?
How can I separate a string by letters and numbers at the same time? For example if I have strings: composto1 = 'H2SO4' composto2 = 'CaCO2' composto3 = 'C20H17' I’ve tried to do: import re…
-
6
votes3
answers331
viewsUnknown cause error: "Syntaxerror: invalid range in Character class"
Situation: I have a page that contains a <iframe> another, on this other page, I have a simple HTML element input: <input type="text" required="" pattern="[a-Z]{2,35}" tabindex="6"…
-
6
votes5
answers23456
viewsAdd character in the middle of a string
Problem How to add character in the middle of a javascript string? For example: var string = "aacc"; // eu quero colocar as letras bb no meio da aa e cc I want the string be of such value aabbcc How…
-
6
votes4
answers18454
viewsHow to replace a certain string within another string in Javascript?
How can I replace only a certain part of a string? Example: var linha_nova = "EU TENHO UM CACHORRO"; I want to replace only the word "UM" on the other. How should I proceed? I also need to replace…
-
6
votes2
answers14324
viewsCheck whether the string is null or empty
How do I check if my variable is empty or null? // Inserção Nome = tf_Nome.getText().toString(); Tipo = tf_Tipo.getText().toString(); Estoque = Integer.valueOf(tf_Estoque.getText().toString());…
-
6
votes3
answers13619
viewsHow to split a string into an array in Javascript?
There is an elegant way to split a string into an array based on the example: var x = "FAT* FAT32*"; And result in something like this: x[0] = "FAT*"; x[1] = "FAT32*";…
-
6
votes2
answers830
viewsConversion from date string to datetime C#
I have a method that will receive a string in the "June 15, 2001" format, for example, which is equivalent to the date to be compared, I need to pass this string to a Datetime, as I would do this…
-
6
votes1
answer305
viewsString para Date
I’m creating some parsers and was doing some tests to develop Date’s. This code: value = '2015-12-31 23:16:00' value = value.replace(/(\d{4}-\d{2}-\d{2}) ?(\d{2}:\d{2})?(:\d{2})?.*/, '$1T$2$3');…
-
6
votes2
answers1113
viewsHow to retrieve specific parts/values/os from a string?
I have a ArrayList where I assemble a custom list that is displayed on a ListView. What I need is to pass the value of the selected item to another screen. See below the method that will call the…
-
6
votes2
answers435
viewsWhat is the rule for converting a binary value to a negative number and vice versa?
I got a gift after the @Maniero answered that question: What is the ~ (til) operator for in PHP? How to obtain the negative value in binary? And how, through torque, to reach a negative value? In…
-
6
votes1
answer407
viewsIs it possible to show exception message in en-BR?
I would like my exception message to be shown in English, someone would know how? catch (Exception ex) { Debug.Writeline(ex.Message); }
-
6
votes2
answers3041
viewsHow to separate the characters of a string in R?
I have values a string containing a date "01/01/2000" I want to separate the day, month and year. #Data #01/01/2000 be it #Dia Mês Ano #01 01 2000 How do I do it in R?…
-
6
votes4
answers2280
viewsString Manipulation - split()
Is there any way to give a split() in a string and on the same line take the position I want? For example: String nome = "Dan Lucio Prada"; String sobrenome = nome.split(" "); //aqui quero pegar só…
-
6
votes5
answers2441
viewsHow to concatenate String within a repeat loop?
I need to put some values together string. How do I concatenate values into one string with a loop of repetition. Example: for($c=0; $c < $tam; $c++){ //concatenar sempre o valor $minhastring =…
-
6
votes3
answers10606
viewsConvert object to String?
What is the best way to convert an object to a type variable int? Or there is no such conversion? Example: if (teste == JOptionPane.OK_OPTION) { int linha = tblPessoa.getSelectedRow(); // Aqui o…
-
6
votes1
answer900
viewsMore elegant ways to invert integers, arrays and strings in Python
Hail! I’ve been looking for elegant ways to do string inversion, arrays and integers in Python. What do you think of my codes below and what suggest to improve them? They work... Thank you! frase =…
-
6
votes2
answers5645
viewsRemove special characters and spaces from a string?
I have a problem, in an app I’m picking up the contacts from the phone book, but I want to do a treatment on the numbers of the contacts that can come like this: (99) 9999-9999 9999-9999 9999 9999…
-
6
votes1
answer310
viewsSearch list elements with partial strings
I have a List<string> who receives the phone number of all the contacts on the phone, until there is no problem, but I want to perform some operations with the elements of that list, but I am…
-
6
votes2
answers704
viewsError replacing occurrence in string using replaceAll
I extract the text from several lines of a PDF, at the beginning of each line I have a configuration of the font size and family used on that line, but then I need to remove this information. First…
-
6
votes4
answers756
viewsRemove a specific space in a string
I’m having trouble implementing replace in a String in Android Studio. I need to remove a certain blank in the String. Real examples: 8 hrs 2 mins 1 day 2 mins I need the text to look like this:…
-
6
votes3
answers3711
viewsHow to shuffle characters from a Java string randomly?
I’m developing a password generator program. In it the user can set the percentage of numbers, letters and special characters that he wants to have in his password, as well as the size of his…
-
6
votes1
answer947
views -
6
votes2
answers86
viewsIs it safe to use Javascript’s String.Concat method in current browsers?
I was observing that in Javascript the object String has a method called concat. Serves to do the same thing as the operator + ago. "Meu nome é " + nome Already with concat would look like this:…
-
6
votes6
answers37862
viewsHow to remove characters from a string?
The program must read two strings and remove from the first string all the letters that occur in the second string. Example: Be the strings "chocolate" and "hollow", then the program should print…
-
6
votes2
answers195
viewsInserting single quotes into null fields
I created a very simple application to simulate a small client registration, but when testing the manipulation of data by the application I could see in the database that the fields that are null in…