CSCI 3327 Visual Basic Chapter 12: Strings, Characters and Regular Expressions UTPA – Fall 2011.

Slides:



Advertisements
Similar presentations
Purpose : To convert this string to a new character array. Return Type : char[ ] Parameters : none Declaration : public char[ ] toCharArray() Returns.
Advertisements

Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
 2003 Prentice Hall, Inc. All rights reserved Fundamentals of Characters and Strings Character constant –Integer value represented as character.
Strings.
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
Java Programming Strings Chapter 7.
Chapter 14 Perl-Compatible Regular Expressions Part 1.
Regular Expression ASCII Converting. Regular Expression Regular Expression is a tool to check if a string matches some rules. It is a very complicated.
1 Query Languages. 2 Boolean Queries Keywords combined with Boolean operators: –OR: (e 1 OR e 2 ) –AND: (e 1 AND e 2 ) –BUT: (e 1 BUT e 2 ) Satisfy e.
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
Fundamental Programming Structures in Java: Strings.
28-Jun-15 String and StringBuilder Part I: String.
 2006 Pearson Education, Inc. All rights reserved Strings, Characters and Regular Expressions.
 Pearson Education, Inc. All rights reserved Strings, Characters and Regular Expressions.
Scripting Languages Chapter 8 More About Regular Expressions.
1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Ten String Manipulation and Menus.
1.
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Characters, String and Regular expressions. Characters char data type is used to represent a single character. Characters are stored in a computer memory.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Computer Programming for Biologists Class 5 Nov 20 st, 2014 Karsten Hokamp
BPJ444: Business Programming Using Java – String Handling Tim McKenna
Sys.Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 18: Regular Expressions in PHP.
PHP Using Strings 1. Replacing substrings (replace certain parts of a document template; ex with client’s name etc) mixed str_replace (mixed $needle,
CSCI 3327 Visual Basic Chapter 12: Strings, Characters and Regular Expressions UTPA – Fall 2011.
Subroutines and Files Bioinformatics Ellen Walker Hiram College.
C# Strings 1 CNS 3260 C#.NET Software Development.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
Hossain Shahriar Announcement and reminder! Tentative date for final exam need to be fixed! Topics to be covered in this lecture(s)
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 8 Strings 1.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
BY Sandeep Kumar Gampa.. What is Regular Expression? Regex in.NET Regex Language Elements Examples Regular Expression API How to Test regex in.NET Conclusion.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
Overview A regular expression defines a search pattern for strings. Regular expressions can be used to search, edit and manipulate text. The pattern defined.
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
C# Strings 1 C# Regular Expressions CNS 3260 C#.NET Software Development.
Regular Expressions. Overview Regular expressions allow you to do complex searches within text documents. Examples: Search 8-K filings for restatements.
Module 6 – Generics Module 7 – Regular Expressions.
Python for NLP Regular Expressions CS1573: AI Application Development, Spring 2003 (modified from Steven Bird’s notes)
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
Chapter 7: Characters, Strings, and the StringBuilder.
20-753: Fundamentals of Web Programming 1 Lecture 10: Server-Side Scripting II Fundamentals of Web Programming Lecture 10: Server-Side Scripting II.
String String Builder. System.String string is the alias for System.String A string is an object of class string in the System namespace representing.
CSC 270 – Survey of Programming Languages
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections UTPA – Fall 2011.
Strings and Related Classes String and character processing Class java.lang.String Class java.lang.StringBuffer Class java.lang.Character Class java.util.StringTokenizer.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
17-Feb-16 String and StringBuilder Part I: String.
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic nd Edition.
 2009 Pearson Education, Inc. All rights reserved. 1 Ch.18 Strings, Characters [and Regular Expressions] Many slides modified by Prof. L. Lilien (even.
Regular Expressions.
Do-more Technical Training
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
University of Central Florida COP 3330 Object Oriented Programming
Strings, Characters and Regular Expressions
String String Builder.
String and StringBuilder
CIS16 Application Development and Programming using Visual Basic.net
String Manipulation and More Controls
Microsoft Visual Basic 2005: Reloaded Second Edition
Visual Programming COMP-315
String Manipulation.
Presentation transcript:

CSCI 3327 Visual Basic Chapter 12: Strings, Characters and Regular Expressions UTPA – Fall 2011

Objectives In this chapter, you will –Learn how to create and manipulate String objects –Get familiar with common methods of String class –Learn how to create and manipulate StringBuilder objects –Know how to use regular expressions in conjunction with classes Regex and Match –Learn how to search for patterns in text using regular expressions 2

Online Chapters URL: – –Chapter 17 - Download: PDF 3

String Class vs. StringBuilder Class String’s contents can never change –Operations that seem to concatenate Strings are in fact creating new Strings StringBuilder class is different 4

StringBuilder Class Imports System.Text Constructor –Dim buffer1 As New StringBuilder() –Dim buffer2 As New StringBuilder(10) –Dim buffer3 As New StringBuilder(“hello”) Initial capacity is the smallest power of two greater than or equal to the number of characters in the argument with a minimum of 16 5

Example 17.9: StringBuilderConstructor.vb URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html 6

Length and Capacity Properties Length property –The number of characters in a StringBuilder object Capacity property –The number of characters that a StringBuilder object can store without allocating more memory 7

Example 17.10: StringBuilderFeatures.vb URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html Function EnsureCapacity(75) Truncate StringBuilder length –buffer.Length = 10 8

Append Method Each method has versions for primitive type and for character arrays, Strings and Objects –buffer.Append(“hello”) –buffer.Append(objectValue) –buffer.Append(characterArray) –buffer.Append(characterArray, 0, 3) Example 17.11: StringBuilderAppend.vb – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html 9

Example 17.12: AppendFormat Method URL: – odeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_htp_2010/c odeexamples.html string1 = “this {0} costs: {1:C}.” buffer.AppendFormat(string1, objectArray) {X[, Y][:FormatString]} –The number of the argument to be formatted (starting from zero) –Y is an optional argument –The String will be padded with spaces {0:D3} – three-digit decimal {0, 4}, {0, -4} 10

Insert and Remove Methods Insert –Primitive types –Character arrays, Strings and Objects Remove(arg1, arg2) –arg1 – the index at which to begin deletion –arg2 – the number of characters to delete 11

Example 17.13: StringBuilderInsertRemove.vb URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html 12

Example 17.14: Replace Method URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html builder.Replace(string1, string2) builder.Replace(“g”c, “G”c, index, count) 13

Char Methods Methods of structure Char –Char.IsDigit(character) –Char.IsLetter(character) –Char.IsLower(character) –Char.IsUpper(character) –Char.IsPunctuation(character) –Char.IsWhiteSpace(character) 14

Example 17.15: SharedCharMethodsForm.vb URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html 15

Regular Expression Formatted strings –E.g. zip code – five digits Imports System.Text.RegularExpressions Regex object –Dim expression As New Regex(“e”) –expression.Match(testString) –expression.Matches(testString) 16

Example 17.16: BasicRegex.vb URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html For Each myMatch In expression.Matches(testString) Quantifier Dim expression As New Regex(“regexp?”) –Alternation Dim expression As New Regex(“(c|h)at”) 17

Character Classes \d –Any digit \w –Any word character \s –Any whitespace 18 \D –Any nondigit \W –Any nonword character \S –Any nonwhitespace

Example 17.18: CharacterClasses.vb URL: – 10/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_htp_20 10/codeexamples.html \w+ \w+? [a-f] [^a-f] [a-zA-Z]+.* 19

Other Quantifiers in Regular Expressions 20

Example 17.20: Validate.vb URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html [\d-[4]] –Any digits other than 4 21

22