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
-
3
votes2
answers2007
viewsConcatenate Strings in C
Good afternoon, you guys! I have a problem in Strings using the C Language. The problem asks the user to enter a name, then to enter a special character, and finally how many times he wants the…
-
3
votes1
answer32
viewsCapture part of the string between certain repeated characters N times
I have a string that has the format of routes: /foo/ /{bar}/ /foo/{bar} /{foo}/{bar} /{foo}/bar/ Can have numerous values between bars, values between {} are variable I wanted to capture all…
-
3
votes2
answers169
viewsWhen to use Stringbuilder and Stringbuffer instead of concatenating with "+" operator in Java?
What are the benefits of concatenating a string using StringBuilder or StringBuffer instead of simply using the operator +?
-
3
votes1
answer219
viewsValidation of string size
I was creating a function to validate large text fields (description, observation, ...), which in SQL will be saved as TEXT, so I basically did this: function($valor, $min = 0, $max = 65000) { if…
-
3
votes1
answer369
viewsHow to run str_detect (stringr) for more than one variable and at once?
I want to filter my database based on two variables: via and city. This filter, however, is made by means of particles of cases present in these two variables. For example, I want to analyze who…
-
3
votes3
answers871
viewsHow to separate characters from a string to a Python list?
How can I convert a string (a word, for example) into a list? entrada: a='carro' saída: ['c', 'a', 'r', 'r', 'o'] I know that by using split, turn into list gets the whole word, like to know if a…
-
3
votes2
answers141
viewsComparison of string characters in C
I’m trying to do an exercise that tests if there’s any white space before a string and remove if you have, but is returning the following error: Segmentation failure (recorded core image) I can’t…
-
3
votes2
answers64
viewsDoubt with string, extract data
I have the following string [{"tipo":"simnao","pergunta":"rwerwerwerewr ?","tag":"#acimadopeso","resposta":"","$$hashkey":"object:410"},{"pergunta":"werwerwerwer…
-
3
votes2
answers131
viewsRegex to extract string content
Good evening, everyone, Thank you for visiting and proposing to help me. I’m terrible at regex so I’ve come to ask for your help. I have the following string that can also vary as example:…
-
3
votes1
answer830
viewsDifference between // and /*...*/
As far as I knew, use // to comment on a line and /*...*/ was the same thing, with the difference that the second covered more than one line if needed. Is there ANY difference between doing // var a…
-
3
votes3
answers1730
viewsChange date format from "yyyy-mm-dd" to "dd/mm/yyyy"
I’m trying to change the shape of a date yyyy-mm-dd for dd/mm/yyyy. I’m using this code: $date = "2019-03-27"; $date1 = new DateTime(date_create_from_format('Y-m-d', $date)->format('d/m/Y'));…
-
3
votes3
answers337
viewsError calling function that returns string in C
I made a program that asks for name and surname to be concatenated through a function: #include <stdio.h> #include <string.h> int main(void){ //Declarando Funçãoo char retornaNome(char…
-
3
votes2
answers1288
viewsReplace last occurrence of "a" in a string
How do I replace the last occurrence of a in a string? var myFrase = prompt(" Digite sua frase aqui: "); for (i = 0; i < myFrase.length; i++) { result = myFrase.charAt(i); if (result == "a") {…
-
3
votes3
answers607
viewsDeclaring a string in C
When setting the size of a string and not using all the space in the reserved memory, after the 0 the rest will be released? char nome[40] = "carlos"; In the above example I declare a string with…
-
3
votes2
answers9963
viewsInvert the words of a sentence, keeping their order in the sentence
I made this algorithm in Python to invert a sentence, in a way it worked, but I need it to reverse the sentence keeping the order of the words. For example: OI TUDO BEM would have to stay IO ODUT…
-
3
votes2
answers91
viewsExtract information from a string
I have the following string I would like to extract only prices within that string thank you in advance a<- " Scarpin Sofia Salto Bloco Slingback TurtleR$269,90 Scarpin Sofia Nobuck Salto Bloco…
-
3
votes1
answer89
viewsConvert all strings to lowercase
There is a way to configure the modelBuider, to lower my strings? For example, when I want all my data of type string, be at my bank a varchar, i make the following configuration:…
-
3
votes3
answers1087
viewsFunction to return letter frequencies in an array
I was trying to do the function that is in the title, but I did not succeed, looking at the solution code for such function, I could not understand, follow the code: function letter_frequency(s) {…
-
3
votes2
answers84
viewsConvert string.match() result to string?
How can I convert the return method match() string? For example: var value:string = ">>>> Ola" var result:string = value.match(/\w+/g) The above example gives error in variable result.…
-
3
votes2
answers81
viewsHow to sort a string by initial fragment?
I need to order a string originating from the git tag -ln. 2019.3.0 Primeira versão totamente integrada com gitlab-ci 2019.3.0-dev0 Aplicado correções sugeridas por py3kwarn 2019.3.0-dev1 refatorado…
-
3
votes3
answers843
viewsShow the amount of each alphabet letter in a String
I’m doing an exercise in Java where the user enters with a sentence. After that, I have to list how many letters there are in the sentence, for example: Input = Daniel Henrique Exit: A = 1 B = 0 C =…
-
3
votes1
answer273
viewsHow to assign a character to a string position?
I’m having some difficulty assigning a character to a certain position of string. I researched a lot before asking here and found nothing. Criticism is always welcome. This function is a part of a…
-
3
votes2
answers767
viewsCompare String Elements in C
I would like to separate a word and compare each element of the string with a letter, I tried to make this comparison using the strcmp() but when executed seems to ignore it, or does not perform.…
-
3
votes1
answer198
viewsHow to create multi-line strings in C++
Have some way to print output, for example a text, without having to print line by line? For example, in Python: print(""" Meu nome eh Guilherme, tenho 19 anos, faço aniversário em Nov. Estudo o…
-
3
votes2
answers613
viewsConvert an Arraylist<String> into a String[]
I need to pass on the values that are in my ArrayList<String> for a String[] because I need to make a setInputData("INPUT",input). I mean, I want to convert the next ArrayList<String>…
-
3
votes2
answers168
viewsString.split() function with separator containing brackets and asterisk
I have the following code: String teste = "meta[[*]]etapa[[*]]especif[[*]]unid[[*]]qtd[[*]]01/01/2000[[*]]02/02/2000[[**]]"; String[] split = teste.split("[[*]]"); for (String string : split) {…
-
3
votes1
answer114
viewsHow to transform string into Date object with Typescript?
I am receiving from the HTML form a string containing the date selected in the pattern dd/mm/yyyy, and want to create an object Date from that string. The problem is that the Date only accepts…
-
3
votes1
answer74
viewsWhy char. Parse(string) returns a number?
I am making a program that uses Typecast, but when I converted a string to char (char.Parse()), received the following return: 115's' What is the reason for the conversion of string to char return a…
-
3
votes2
answers239
viewsWhat is the difference between ", " and "+" in Python?
In a code mensagem = "ola " nome = input("Diga seu nome ") print (mensagem + nome ) mensagem = "ola" nome = input("Diga seu nome ") print (mensagem , nome ) The two do the same function , with the…
-
3
votes3
answers230
viewsRemove lowercase letters from a list
I was trying to make a program that could identify whether a letter is in upper case or in Lower case in a list, so that it would delete the lower case letters. frase = ("A B C D e f g h") new =…
-
3
votes1
answer198
viewsMethod "include?" returning false when there is a character in the Ruby string
I’m a beginner in Ruby and I’m trying to create a Hangman game to test my language skills. In a part of the code, I need to get a letter chosen by the user and check if that letter is present in the…
-
3
votes2
answers272
viewsFunction that compares characters from a string and returns true or false
I’m trying to make a function that should return true or false if the first and last characters are equal. However, comparing them is giving error of out of range and I can’t identify the reason:…
-
3
votes2
answers91
viewsreplace more than one char utitlizando . replace()
I have the following function: public String replaceCharToNull(int row, int colum) { String result; result = (((String)jTableLoan.getModel().getValueAt(row, colum)).replace("x", "")); return result;…
-
3
votes2
answers63
viewsWhat does the %u do?
I’ve been doing a list exercise on strings and researched examples. One of the codes was this: /* strlen example */ #include <stdio.h> #include <string.h> int main () { char…
-
3
votes1
answer157
viewsWhat is the difference between string find and index methods in Python?
I always use the method index to fetch the index of a character in a string in Python. I recently discovered the method find() and I noticed that he does exactly the same thing. Example: name="Alan…
-
3
votes1
answer125
viewsWhere does the memory space required for each element in a C string array come from?
In C, you can group a set of string's, which are arrays of char's within a array without having to define 2 dimensions for this? That’s why you use a array pointer char's and simply defines the…
-
3
votes1
answer42
viewsStandardize phone number with REGEX on R
library(tidyverse) I’m trying to standardize the "numero_telefonico" column of this dataset: https://raw.githubusercontent.com/rivaquiroga/latinr-taller-regex/master/datos/telefonos.csv Download the…
-
3
votes4
answers167
viewsHow to return the first vowel of several words in a list?
The code is partially done, but it returns only the vowels found in each word. How could I return only the first vowel of each word? palavras = ('boi', 'vaca', 'macaco', 'ovelha', 'lesma',) vogais =…
-
3
votes2
answers149
viewsHow to swap the last character in a string?
I’m having a problem at the time of leaving the last null value to be inserted in a button that will erase the value that the user type, I tried to use the for to solve this problem, but did not…
-
3
votes1
answer73
viewsIdentify accented letters and print a warning
I need to make a program that accepts only letters without accent, and for that I’m trying to do something that identifies a letter with accent and then print a warning about the error, but when I…
-
3
votes2
answers168
viewsPython 3: How to understand this string
I have a question, I am a beginner and I am reading the book "Introduction to Programming with Python" 3° Edition. And I came across this code below. Program 4.3 - Income Tax Calculation salario =…
-
3
votes2
answers85
viewsFormatting to number of decimals dynamically using Python
import math def formating_pi(n): a= "pi com {:c} casas decimais é {:.17}" return a.format(n, math.pi) formating_pi(5) I’d like to not put the number 17 explicitly, but rather the result of the…
-
3
votes3
answers114
viewsReading undesirable characters - Python
A way to separate words from a string provided as in the method below: entrada = input().split(" ") Doubt: If I want to exclude more than one specific character (" ,&ˆ*!!:") not necessarily in…
-
3
votes1
answer59
viewsConvert a Double with more than 13 decimal places to String without losing values
I have in C# the following number in Double: 124.00767638369544. When I simply put valor.toString(), the value goes to: 124.007676383695, IGNORING the 0,00000000000044. The system I’m making needs…
-
3
votes2
answers293
viewsReplace string chunk between 2 indexes
I have a long string inside a txt file, for example, let’s say my string is about that: strg = '123456 BANANA 00 SP' In position 14 and 15 we have the "00", I’m gonna need to replace up front The…
-
3
votes1
answer142
viewsRegex is not checking the accented character, even though it is in the expression
I have the following Python regex to filter my application text input: import re good_chars_regexp = re.compile(r"^[A-Za-záéíóúÁÉÍÓÚâêîôÂÊÎÔãõÃÕçÇ00-9\,\.\-\?\"\'\’\!\“\s\;\:\“\”\–\‘\’\’\/\\]+$",…
-
3
votes1
answer64
viewsWhat is the best way to check if a string has any of these words?
I have a question, consider the following: nomes_proibidos = ['Corona', 'Clorivaldo', 'Pfizernaldo', 'Hulk', 'Naruto', 'Goku', 'Cloroquina'] def verificar_nome(n): for nome in nomes_proibidos: if…
-
3
votes1
answer101
viewsImprove performance in iteration
I have a C# method that receives a List<string> and I must return a string with the list of members of the List<string> ordered by number of occurrences and then alphabetically. I did…
-
3
votes2
answers84
viewsHow to return the last character of a String in C++?
I want to make a program that shows on the screen the last character of a String. In Python it would be something like this: nome = "Teste" print(nome[-1]) Upshot: and So I tried to adapt it to C++:…
-
3
votes1
answer133
viewsWhat is the use of "." (dot) in PHP’s ltrim, rtrim and Trim functions?
I was here doing a feature, where I needed to remove some characters from the beginning of a string, and I wasn’t really in the mood to use regex for that. I tried to use the function ltrim, since…