SlideShare une entreprise Scribd logo
1  sur  3
Télécharger pour lire hors ligne
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

Contenu connexe

En vedette

Carryover effects of joint attention to repeated events in chimpanzees and yo...
Carryover effects of joint attention to repeated events in chimpanzees and yo...Carryover effects of joint attention to repeated events in chimpanzees and yo...
Carryover effects of joint attention to repeated events in chimpanzees and yo...
Francys Subiaul
 
C V of Hanan Ghawas - 03092015
C V  of Hanan Ghawas - 03092015C V  of Hanan Ghawas - 03092015
C V of Hanan Ghawas - 03092015
HANAN Ghawas
 
Maritime Academies - Final Report and annexes_template EC_0.PDF
Maritime Academies - Final Report and annexes_template EC_0.PDFMaritime Academies - Final Report and annexes_template EC_0.PDF
Maritime Academies - Final Report and annexes_template EC_0.PDF
George Triantaphyllidis
 
Ronald mendoza-4to.-compu.-ejercicio-de-laboratorio
Ronald mendoza-4to.-compu.-ejercicio-de-laboratorioRonald mendoza-4to.-compu.-ejercicio-de-laboratorio
Ronald mendoza-4to.-compu.-ejercicio-de-laboratorio
ronald mendoza
 
Conciertomatutino
ConciertomatutinoConciertomatutino
Conciertomatutino
Jorge Llosa
 
Tatawin midoun presentation v16
Tatawin midoun presentation v16Tatawin midoun presentation v16
Tatawin midoun presentation v16
ELYAS90
 
Julio, david s, jorge fotoroman
Julio, david s, jorge fotoromanJulio, david s, jorge fotoroman
Julio, david s, jorge fotoroman
solandadigital
 
Herman Dune Press Update
Herman Dune Press UpdateHerman Dune Press Update
Herman Dune Press Update
CitySlang
 
Algebra moderna schaum
Algebra moderna   schaumAlgebra moderna   schaum
Algebra moderna schaum
Nicole Gomez
 

En vedette (17)

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

Similaire à Strings

The java program that display a menu of choices and p.pdf
   The java program that display a menu of choices  and p.pdf   The java program that display a menu of choices  and p.pdf
The java program that display a menu of choices and p.pdf
annaistrvlr
 
import java.util.Scanner;public class AuthoringAssistant {    .pdf
import java.util.Scanner;public class AuthoringAssistant {    .pdfimport java.util.Scanner;public class AuthoringAssistant {    .pdf
import java.util.Scanner;public class AuthoringAssistant {    .pdf
noelbuddy
 
Python language data types
Python language data typesPython language data types
Python language data types
Harry Potter
 
Python language data types
Python language data typesPython language data types
Python language data types
Young Alista
 
Python language data types
Python language data typesPython language data types
Python language data types
Luis Goldster
 
Python language data types
Python language data typesPython language data types
Python language data types
Tony Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data types
Fraboni Ec
 
Python language data types
Python language data typesPython language data types
Python language data types
James Wong
 

Similaire à Strings (20)

The java program that display a menu of choices and p.pdf
   The java program that display a menu of choices  and p.pdf   The java program that display a menu of choices  and p.pdf
The java program that display a menu of choices and p.pdf
 
import java.util.Scanner;public class AuthoringAssistant {    .pdf
import java.util.Scanner;public class AuthoringAssistant {    .pdfimport java.util.Scanner;public class AuthoringAssistant {    .pdf
import java.util.Scanner;public class AuthoringAssistant {    .pdf
 
Strings v.1.1
Strings v.1.1Strings v.1.1
Strings v.1.1
 
Template Haskell
Template HaskellTemplate Haskell
Template Haskell
 
Learn python in 20 minutes
Learn python in 20 minutesLearn python in 20 minutes
Learn python in 20 minutes
 
String
StringString
String
 
Arduino creative coding class part iii
Arduino creative coding class part iiiArduino creative coding class part iii
Arduino creative coding class part iii
 
14 strings
14 strings14 strings
14 strings
 
[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
 
Programming ppt files (final)
Programming ppt files (final)Programming ppt files (final)
Programming ppt files (final)
 
3 character strings and formatted input output
3  character strings and formatted input output3  character strings and formatted input output
3 character strings and formatted input output
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python
PythonPython
Python
 

Plus de Cody Mims

Plus de Cody Mims (20)

Rotational motion
Rotational motionRotational motion
Rotational motion
 
Bandwagon billboard
Bandwagon billboardBandwagon billboard
Bandwagon billboard
 
Story of an Hour mythological analysis
Story of an Hour mythological analysisStory of an Hour mythological analysis
Story of an Hour mythological analysis
 
Psychology review
Psychology reviewPsychology review
Psychology review
 
Merger conglomerate-multinational worksheet
Merger conglomerate-multinational worksheetMerger conglomerate-multinational worksheet
Merger conglomerate-multinational worksheet
 
Abnormal psychology
Abnormal psychologyAbnormal psychology
Abnormal psychology
 
Stages of psychosexual development
Stages of psychosexual developmentStages of psychosexual development
Stages of psychosexual development
 
Motivation
MotivationMotivation
Motivation
 
Cognition
CognitionCognition
Cognition
 
Sophienburg history scholarship
Sophienburg history scholarshipSophienburg history scholarship
Sophienburg history scholarship
 
Sleep
SleepSleep
Sleep
 
States of consciousness
States of consciousnessStates of consciousness
States of consciousness
 
Sensory perceptory
Sensory perceptorySensory perceptory
Sensory perceptory
 
Developmental psychology
Developmental psychologyDevelopmental psychology
Developmental psychology
 
Angular Motion notes
Angular Motion notesAngular Motion notes
Angular Motion notes
 
Introspection
IntrospectionIntrospection
Introspection
 
Psychology
PsychologyPsychology
Psychology
 
Temperance
TemperanceTemperance
Temperance
 
Executive branch review
Executive branch reviewExecutive branch review
Executive branch review
 
Executive branch worksheet
Executive branch worksheetExecutive branch worksheet
Executive branch worksheet
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 

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