Chapter 3 String manipulation.

Slides:



Advertisements
Similar presentations
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Advertisements

Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Enter question text... 1.Enter answer text.... Enter question text... 1.Enter answer text...
Enter question text... 1.Enter answer text.... Enter question text... 1.Enter answer text...
If – Case Programs CSC Arwa © 2008.
פתרון בוחן הכיתה. שאלה #1 Module Module1 Sub Main() Dim x, z As Integer x = Console.ReadLine() z = Console.ReadLine() If (x = 0) Then Console.WriteLine("Error")
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
Implementing Control Logic in C# Svetlin Nakov Telerik Corporation
(c) Bob McKillop, 2006Tutorial #1 T1-1 Tutorial #1 - your first compiled code  the learning objectives for this tutorial are very modest q compile and.
05/09/2015SJF L31 F21SF Software Engineering Foundations Formatting Converting numbers to Strings and vice versa Monica Farrow EM G30
Introduction to Classes and Objects (Through Ch 5) Dr. John P. Abraham Professor UTPA.
Reading and Writing to the Console Svetlin Nakov Telerik Corporation
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
The char Data Type A char is a one byte integer type typically used for storing characters. Example: char oneLetter = ’D’; We enclose the character in.
CSCI 3327 Visual Basic Chapter 12: Strings, Characters and Regular Expressions UTPA – Fall 2011.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
Programming with C# Iteration LECTURE 3. Summary of last lecture SequenceSelectionif and switch statementsCastingRandom.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
Iteration (Loop) partI Thanachat Thanomkulabut. Consider the following program! using System; Namespace SimPleExample { class SimPleC { class SimPleC.
Manipulating Text In today’s lesson we will look at: why we might want to pick out parts of text strings some BASIC functions that can be used to chop.
Chapter 3:Decision Structures.  3.1 The if Statement  3.2 The if-else Statement  3.3 The if-else-if Statement  3.4 Nested if Statements  3.5 Logical.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
Reading and Writing to the Console Svetlin Nakov Telerik Corporation
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
Methods SWE 344 Internet Protocols & Client Server Programming.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
1 Microsoft® Visual Basic®.NET Language # 1. 2 Variable Declaring Variable Dim {VariableName} As {Type} Dim {VariableName} As {Type} = {value} Example:
CIS 3301 C# Lesson 3 Control Statements - Selection.
C++ Programming Lecture 7 Control Structure I (Selection) – Part II The Hashemite University Computer Engineering Department.
Console Input / Output Reading and Writing to the Console SoftUni Team Technical Trainers Software University
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
Introducing Dreamweaver. Dreamweaver The web development application used to create web pages Part of the Adobe creative suite.
5 February 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Interpolation Variable Interpolation, Backslash Interpolation.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
Microsoft Access Prepared by the Academic Faculty Members of IT.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline Counter-Controlled Repetition: Example Sentinel-Controlled Repetition:
Declaring variables The type could be: int double char String name is anything you want like lowerCaseWord.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
Characters must also be encoded in binary. ASCII maps characters to numbers.
Introduction to Programming
C# Basic Syntax, Visual Studio, Console Input / Output
C# Basic Syntax, Visual Studio, Console Input / Output
Using the Console.
COMP 170 – Introduction to Object Oriented Programming
Data Types, Arithmetic Operations
Compiler Design First Lecture.
Chapter 4: Making Decisions.
Method Mark and Lyubo.
Control Statement Examples
Operators and Expressions
The University of Texas – Pan American
Advanced Programming Lecture 02: Introduction to C# Apps
Introduction to Programming with Python
Introduction to Java Programming
Variables, Loops, Decision Statements, etc
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises UTPA – Fall 2012 This set of slides is revised from.
Please enter text Please enter text DD/MM/YY Please enter text
Chapter 3 – Introduction to C# Programming
Module5 Looping Techniques: Part 2
Module5 Looping Techniques: Part 2
What's wrong with Easter jokes? They crack you up
CSE Module 1 A Programming Primer
Var Name =Console . ReadLine();
Chapter 5 – Control Structures: Part 2
Welcome back to Software Development!
Arrays and Strings CSCI293 - C# September 26, 2005.
CSE Module 1 A Programming Primer
C++ Programming Lecture 7 Control Structure I (Selection) – Part II
Presentation transcript:

Chapter 3 String manipulation

Lowercase? string.ToLower(); Example: string name = “JONES”; string lastname = name.ToLower(); Or Console.WriteLine(“Name: {0}”, name.ToLower()); Result: lastname=“jones”;

Uppercase string.ToUpper(); Example: string name = “jones”; string lastname = name.ToUpper(); Result: lastname=“JONES”;

Length How long is the string? int howlong; string text = “this is a sentence”; howlong = text.Length();

Padding Sometimes you want to print a field so that it occupies a fixed number of spaces (eg 20) string text = “Hello”; Console.WriteLine(“show ”+ text.PadRight(20,’ ’); Or Console.WriteLine(“show ”+ text.PadLeft(20,’ ’);

Padding Example string number = Convert.ToString(200.55); Console.WriteLine(“Padded unpadded”); Console.WriteLine(“{0} {1} {2}”, number.PadRight(15,’ ’), number, number; Result: Padded unpadded 200.55 200.55 200.55

double salary=400.456;double tax = salary*.02; double net = salary - tax; string strsal, strtax, strnet; strsal = String.Format("{0:N2}",salary); strtax = String.Format("{0:N2}",tax); strnet = String.Format("{0:N2}",net); string hdsal="salary".PadRight(15,' '); string hdtax="tax".PadRight(15,' '); string hdnet="net".PadRight(15,' '); Console.WriteLine("{0} {1} {2}",hdsal,hdtax, hdnet); Console.WriteLine("{0} {1} {2}",strsal.PadRight(15,' '), strtax.PadRight(15,' '),strnet.PadRight(15,' ')); result salary tax net 400.46 8.01 392.45

Menus Please enter your choice: 1 List 2 Alpha 3 By zipcode

Menus… string text; while (selector != 0) { int selector=1; string text; while (selector != 0) { Console.Write(“Please enter your choice:\n ”); Console.Write(“1. List\n2. Alpha\n3. By Zip ”); selector = Convert.ToInt32 (Console.ReadLine()); if (selector !=0) Console.Write (“Please enter text ”); text = Console.ReadLine();}//end if

Menu continued switch (selector) { case 0: Console.WriteLine(“The end”); break; case 1: Console.WriteLine(“Code for List ”); case 2: default: break;}// end switch