SlideShare a Scribd company logo
Thursday, October 9, 2014
Strings!
Computer Science
- Concatenation–a series of interconnected things or events. "a singular concatenation
of events unlikely to recur" synonyms: series, sequence, succession, chain!
- First and foremost is concatenation. We use the plus sign, +, to do this. For
example:!
String mm = "Hello";!
String nx = "good buddy";!
String c = mm + nx;!
System.out.println(c); //prints Hellogood buddy…notice no space between o &
g!
- The above code could also have been done in the following way:!
String mm = "Hello";!
String nx = "good buddy";!
System.out.println(mm + " " + nx); //prints Hello good buddy…notice the space!
- We could also do it this way:!
System.out.println("Hello" !
- length( ) method, find the number of characters in a String!
int len = theName.length( );!
System.out.println(len); //space is counted!
- Pick out a piece of a String…substring!
String myPet = "Sparky the dog";!
String smallPart = myPet.substring(4);!
System.out.println(smallPart); //prints ky the dog
S P A R K Y T H E D O G
0 1 2 3 4 5 6 7 8 9 10 11 12 13
1
Thursday, October 9, 2014
string smallPar = myPet.substring(4, 12);!
System.out.println(smallPart); //prints ky the d!
- toLowerCase converts all characters to lower case!
String bismark = "Dude, where's MY car?"!
System.out.println( bismark toLowerCase( ) ); //prints dude, where's my car?!
- toUpperCase converts all characters to upper case!
System.out.println( "Dude, where's My car? toUpperCase( ) );!
//prints DUDE, WHERE'S MY CAR?!
- Note: length, substring, toLowerCase, and toUpperCase are all methods of the
String class.!
- It is possible to concatenate a String with a numeric variable as follows:!
int x = 27!
String s = "Was haben wir gemacht?"; //German for "What have we done?"!
String combo = s + " " + x;!
System.out.println(combo); //prints Was haben wir gimacht? 27!
- How do we force a quote character (") to printout.... or, to be part of a String. Use the
escape sequence, ", to print the following (note escape sequences always start with
the  character.!
- What "is" the right way?
String s = "What "is" the right way?"!
- Another escape sequence, n, will create a new line (also called line break) as
shown below:!
String s = "Here is one linenand here is another";!
System.out.println(s)!
- The escape sequence, , will allow us to print a backslash within our String.
Otherwise, if we try to insert just a single  it will be interpreted as the beginning of an
escape sequence.!
System.out.println("Path = c:nerd_file.doc")!
2
Thursday, October 9, 2014
- Prints the following:!
Path = c:nerd_file.doc
- The escape sequence, t, will allow us to "tab" over. The following code tabs twice.
3

More Related Content

PPTX
Automata presentation turing machine programming techniques
PDF
Dicas de SSH
PPTX
PROLOG: Cuts And Negation In Prolog
PDF
Ms access modules
KEY
VIM for the PHP Developer
PDF
As novidades do WordPress 3.0 para criativos
PDF
Vim cheat-sheet-en
PPTX
Plegable biomol
Automata presentation turing machine programming techniques
Dicas de SSH
PROLOG: Cuts And Negation In Prolog
Ms access modules
VIM for the PHP Developer
As novidades do WordPress 3.0 para criativos
Vim cheat-sheet-en
Plegable biomol

Viewers also liked (17)

PPT
Bathroomsplus-review
ODP
Ejemplo De PresentacióN
PDF
Carryover effects of joint attention to repeated events in chimpanzees and yo...
PDF
C V of Hanan Ghawas - 03092015
PDF
Maritime Academies - Final Report and annexes_template EC_0.PDF
PPT
Qué es Lur Gozoa
PPTX
En busca de mi futuro
PPTX
histori de la computacion
PPTX
Ronald mendoza-4to.-compu.-ejercicio-de-laboratorio
PPT
El Problema
PPS
Conciertomatutino
PPTX
Tatawin midoun presentation v16
PPTX
Julio, david s, jorge fotoroman
PPS
Adultos mayores
PDF
Herman Dune Press Update
PDF
Algebra moderna schaum
PPTX
Optimiser votre présence sur plusieurs places de marché
Bathroomsplus-review
Ejemplo De PresentacióN
Carryover effects of joint attention to repeated events in chimpanzees and yo...
C V of Hanan Ghawas - 03092015
Maritime Academies - Final Report and annexes_template EC_0.PDF
Qué es Lur Gozoa
En busca de mi futuro
histori de la computacion
Ronald mendoza-4to.-compu.-ejercicio-de-laboratorio
El Problema
Conciertomatutino
Tatawin midoun presentation v16
Julio, david s, jorge fotoroman
Adultos mayores
Herman Dune Press Update
Algebra moderna schaum
Optimiser votre présence sur plusieurs places de marché
Ad

Similar to Strings (20)

PDF
The java program that display a menu of choices and p.pdf
PDF
import java.util.Scanner;public class AuthoringAssistant {    .pdf
PPTX
Day5 String python language for btech.pptx
PPT
Strings v.1.1
PDF
Template Haskell
PPTX
Learn python in 20 minutes
PDF
String
PDF
Arduino creative coding class part iii
PPT
14 strings
PDF
[ITP - Lecture 17] Strings in C/C++
PPTX
Introduction to TypeScript
PPTX
Java_Predefined_Methods_Presentation.pptx
PPTX
Programming ppt files (final)
PDF
3 character strings and formatted input output
PPTX
Python language data types
PPTX
Python language data types
PPTX
Python language data types
PPTX
Python language data types
PPTX
Python language data types
PPTX
Python language data types
The java program that display a menu of choices and p.pdf
import java.util.Scanner;public class AuthoringAssistant {    .pdf
Day5 String python language for btech.pptx
Strings v.1.1
Template Haskell
Learn python in 20 minutes
String
Arduino creative coding class part iii
14 strings
[ITP - Lecture 17] Strings in C/C++
Introduction to TypeScript
Java_Predefined_Methods_Presentation.pptx
Programming ppt files (final)
3 character strings and formatted input output
Python language data types
Python language data types
Python language data types
Python language data types
Python language data types
Python language data types
Ad

More from Cody Mims (20)

PPTX
Rotational motion
PDF
Bandwagon billboard
PPTX
Story of an Hour mythological analysis
DOCX
Psychology review
DOCX
Merger conglomerate-multinational worksheet
DOCX
Abnormal psychology
DOCX
Stages of psychosexual development
DOCX
Motivation
DOCX
Cognition
DOCX
Sophienburg history scholarship
DOCX
Sleep
DOCX
States of consciousness
DOCX
Sensory perceptory
DOCX
Developmental psychology
DOCX
Angular Motion notes
DOCX
Introspection
DOCX
Psychology
DOCX
Temperance
DOCX
Executive branch review
DOCX
Executive branch worksheet
Rotational motion
Bandwagon billboard
Story of an Hour mythological analysis
Psychology review
Merger conglomerate-multinational worksheet
Abnormal psychology
Stages of psychosexual development
Motivation
Cognition
Sophienburg history scholarship
Sleep
States of consciousness
Sensory perceptory
Developmental psychology
Angular Motion notes
Introspection
Psychology
Temperance
Executive branch review
Executive branch worksheet

Recently uploaded (20)

PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
A Presentation on Artificial Intelligence
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Mushroom cultivation and it's methods.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
August Patch Tuesday
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Enhancing emotion recognition model for a student engagement use case through...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
OMC Textile Division Presentation 2021.pptx
A comparative analysis of optical character recognition models for extracting...
DP Operators-handbook-extract for the Mautical Institute
WOOl fibre morphology and structure.pdf for textiles
cloud_computing_Infrastucture_as_cloud_p
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
Unlocking AI with Model Context Protocol (MCP)
Hindi spoken digit analysis for native and non-native speakers
A Presentation on Artificial Intelligence
Zenith AI: Advanced Artificial Intelligence
Web App vs Mobile App What Should You Build First.pdf
Mushroom cultivation and it's methods.pdf
NewMind AI Weekly Chronicles - August'25-Week II
August Patch Tuesday
Digital-Transformation-Roadmap-for-Companies.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Strings

  • 1. Thursday, October 9, 2014 Strings! Computer Science - Concatenation–a series of interconnected things or events. "a singular concatenation of events unlikely to recur" synonyms: series, sequence, succession, chain! - First and foremost is concatenation. We use the plus sign, +, to do this. For example:! String mm = "Hello";! String nx = "good buddy";! String c = mm + nx;! System.out.println(c); //prints Hellogood buddy…notice no space between o & g! - The above code could also have been done in the following way:! String mm = "Hello";! String nx = "good buddy";! System.out.println(mm + " " + nx); //prints Hello good buddy…notice the space! - We could also do it this way:! System.out.println("Hello" ! - length( ) method, find the number of characters in a String! int len = theName.length( );! System.out.println(len); //space is counted! - Pick out a piece of a String…substring! String myPet = "Sparky the dog";! String smallPart = myPet.substring(4);! System.out.println(smallPart); //prints ky the dog S P A R K Y T H E D O G 0 1 2 3 4 5 6 7 8 9 10 11 12 13 1
  • 2. Thursday, October 9, 2014 string smallPar = myPet.substring(4, 12);! System.out.println(smallPart); //prints ky the d! - toLowerCase converts all characters to lower case! String bismark = "Dude, where's MY car?"! System.out.println( bismark toLowerCase( ) ); //prints dude, where's my car?! - toUpperCase converts all characters to upper case! System.out.println( "Dude, where's My car? toUpperCase( ) );! //prints DUDE, WHERE'S MY CAR?! - Note: length, substring, toLowerCase, and toUpperCase are all methods of the String class.! - It is possible to concatenate a String with a numeric variable as follows:! int x = 27! String s = "Was haben wir gemacht?"; //German for "What have we done?"! String combo = s + " " + x;! System.out.println(combo); //prints Was haben wir gimacht? 27! - How do we force a quote character (") to printout.... or, to be part of a String. Use the escape sequence, ", to print the following (note escape sequences always start with the character.! - What "is" the right way? String s = "What "is" the right way?"! - Another escape sequence, n, will create a new line (also called line break) as shown below:! String s = "Here is one linenand here is another";! System.out.println(s)! - The escape sequence, , will allow us to print a backslash within our String. Otherwise, if we try to insert just a single it will be interpreted as the beginning of an escape sequence.! System.out.println("Path = c:nerd_file.doc")! 2
  • 3. Thursday, October 9, 2014 - Prints the following:! Path = c:nerd_file.doc - The escape sequence, t, will allow us to "tab" over. The following code tabs twice. 3