0% found this document useful (0 votes)
2 views2 pages

String

A string is a sequence of characters used to represent text, commonly found in programming languages. Strings can include various characters, are often immutable, and are enclosed in quotes. The document also covers string operations, examples in different programming languages, and the distinction between strings and other data types.

Uploaded by

shinde09kanak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

String

A string is a sequence of characters used to represent text, commonly found in programming languages. Strings can include various characters, are often immutable, and are enclosed in quotes. The document also covers string operations, examples in different programming languages, and the distinction between strings and other data types.

Uploaded by

shinde09kanak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

📘 What is a String?

A string is a sequence of characters used to represent text. It's one of the most
commonly used data types in almost every programming language.

🔹 String Characteristics:
Can include letters, numbers, symbols, whitespace

Enclosed in quotes (single ' ', double " ", or backticks `, depending on the
language)

Immutable in many languages (cannot be changed once created)

✅ Examples of Strings:
text
Copy
Edit
"Hello World"
'12345'
"Welcome to India!"
'@#&$%'
" "
"John_Doe_99"
"true" ← (Note: This is a string, **not** a boolean)
🔸 Strings in Popular Programming Languages
🔹 Python
python
Copy
Edit
s1 = "Hello"
s2 = 'World'
s3 = "123"
s4 = "Hello " + "World" # Concatenation
print(s4.upper()) # HELLO WORLD
🔹 Java
java
Copy
Edit
String s1 = "Hello";
String s2 = "World";
System.out.println(s1 + " " + s2); // Hello World
System.out.println(s1.length()); // 5
🔹 JavaScript
javascript
Copy
Edit
let str1 = "Hello";
let str2 = 'World';
let str3 = `Name: ${str1}`; // Template literal
console.log(str1 + " " + str2); // Hello World
🔹 C
c
Copy
Edit
char str[] = "Hello";
printf("%s", str); // Output: Hello
🔹 Common String Operations:
Operation Example Description
Length "hello".length Returns number of characters
Concatenation "hello" + " world" Joins two strings
Upper/Lower "Hello".toUpperCase() HELLO
Substring "Hello".substring(1, 3) "el"
Replace "abc".replace("a", "x") "xbc"
Trim " hi ".trim() "hi"
Split "a,b,c".split(",") ["a", "b", "c"]
IndexOf "hello".indexOf("e") 1
CharAt "hello".charAt(1) "e"

🔸 String Escape Characters


Escape Meaning
\n New line
\t Tab
\\ Backslash
\" Double quote
\' Single quote

Example:

python
Copy
Edit
print("Hello\nWorld")
# Output:
# Hello
# World
🔹 String vs Other Types
Type Example Description
String "123" Text
Integer 123 Number (no quotes)
Boolean true Logical (true/false)
Character 'A' Single character (Java, C)

You might also like