Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [string]

A string is a finite sequence of symbols, commonly used for text, though sometimes for arbitrary data.

7555 votes
68 answers
1.3m views

What is the difference between String and string in C#?

What are the differences between these two, and which one should I use? string s = "Hello world!"; String s = "Hello world!";
7406 votes
3 answers
8.1m views

How to check whether a string contains a substring in JavaScript?

Usually I would expect a String.contains() method, but there doesn't seem to be one. What is a reasonable way to check for this?
5478 votes
50 answers
4.6m views

How do I replace all occurrences of a string in JavaScript?

Given a string: string = "Test abc test test abc test test test abc test test abc"; This seems to only remove the first occurrence of abc in the string above: string = string.replace('abc', ...
Ali's user avatar
  • 266k
5275 votes
106 answers
4.2m views

How do I make the first letter of a string uppercase in JavaScript?

How do I make the first character of a string uppercase if it's a letter, but not change the case of any of the other letters? For example: "this is a test" �� "This is a test" &...
Robert Wills's user avatar
  • 53.4k
4742 votes
66 answers
2.7m views

How do I read / convert an InputStream into a String in Java?

If you have a java.io.InputStream object, how should you process that object and produce a String? Suppose I have an InputStream that contains text data, and I want to convert it to a String, so for ...
Johnny Maelstrom's user avatar
3851 votes
17 answers
520k views

Why is char[] preferred over String for passwords?

In Swing, the password field has a getPassword() (returns char[]) method instead of the usual getText() (returns String) method. Similarly, I have come across a suggestion not to use String to handle ...
Ahamed's user avatar
  • 39.6k
3786 votes
23 answers
5.1m views

Convert bytes to a string in Python 3

I captured the standard output of an external program into a bytes object: >>> from subprocess import * >>> stdout = Popen(['ls', '-l'], stdout=PIPE).communicate()[0] >>> ...
Tomas Sedovic's user avatar
3586 votes
10 answers
6.9m views

Does Python have a string 'contains' substring method?

I'm looking for a string.contains or string.indexof method in Python. I want to do: if not somestring.contains("blah"): continue
Blankman's user avatar
  • 265k
3566 votes
30 answers
3.2m views

How to check if a string contains a substring in Bash

I have a string in Bash: string="My string" How can I test if it contains another string? if [ $string ?? 'foo' ]; then echo "It's there!" fi Where ?? is my unknown operator. ...
davidsheldon's user avatar
  • 39.5k
3512 votes
30 answers
6.8m views

How do I convert a String to an int in Java?

How can I convert a String value to an int type? "1234" → 1234
Unknown user's user avatar
  • 45.1k
3474 votes
43 answers
2.4m views

How to assign a multiline string literal to a variable?

How do I convert this Ruby code with a multiline string into JavaScript? text = <<"HERE" This Is A Multiline String HERE
Newy's user avatar
  • 39.8k
3449 votes
32 answers
1.3m views

Case insensitive 'Contains(string)'

Is there a way to make the following return true? string title = "ASTRINGTOTEST"; title.Contains("string"); There doesn't seem to be an overload that allows me to set the case ...
Boris Callens's user avatar
3362 votes
84 answers
2.4m views

How do I iterate over the words of a string?

How do I iterate over the words of a string composed of words separated by whitespace? Note that I'm not interested in C string functions or that kind of character manipulation/access. I prefer ...
2852 votes
95 answers
3.0m views

Generate random string/characters in JavaScript

I want a 5 character string composed of characters picked randomly from the set [a-zA-Z0-9]. What's the best way to do this with JavaScript?
Tom Lehman's user avatar
  • 88.2k
2851 votes
40 answers
2.3m views

Extract filename and extension in Bash

I want to get the filename (without extension) and the extension separately. The best solution I found so far is: NAME=`echo "$FILE" | cut -d'.' -f1` EXTENSION=`echo "$FILE" | cut -d'.' -f2` This ...
ibz's user avatar
  • 45.9k

15 30 50 per page
1
2 3 4 5
12318