Professional Documents
Culture Documents
String manipulation
String formatting
in C# Stringbuilder and string methods
Regular expressions
Lecture 9
CS 638 Web Programming – Estan & Kivolowitz CS 638 Web Programming – Estan & Kivolowitz
CS 638 Web Programming – Estan & Kivolowitz CS 638 Web Programming – Estan & Kivolowitz
1
Regular expressions Example regular expressions 1
A regular expression (regex) is a compact way of Regex Strings that match Strings that don’t match
representing a certain type of pattern a “abc”,“cba” “xyz”
CS 638 Web Programming – Estan & Kivolowitz CS 638 Web Programming – Estan & Kivolowitz
CS 638 Web Programming – Estan & Kivolowitz CS 638 Web Programming – Estan & Kivolowitz
Regular expressions in C#
Implemented by the class
System.Text.RegularExpressions.Regex C# programming
Constructor accepts a string describing the regular
expression that is “compiled” to a representation
used for efficient matching Lectures 6 - 9
Important methods
IsMatch(string input) checks if input string matches
Replace(string input, string replacement)
replaces all matches of the regular expression in input CS 638 Web Programming
Split(string input) splits input interpreting each
match of the regex as a separator
See demo4 for examples on how to use regexes
2
Differences between
C# and Java Application structure
Application structure Namespaces similar to Java packages, but
decoupled from how source code is structured
Inheritance and polymorphism
Multiple classes can be defined in a single file, name
Value types and parameter passing of classes unrelated to file name
Syntax changes and extensions C# partial classes – a class defined in multiple files
For more detailed comparison that goes Assemblies similar to jar files
beyond the things we covered in class see C#’s keyword internal is like Java’s protected
http://www.25hoursaday.com/CsharpVsJava.html – grants access to others from same assembly
In C# protected grants access to derived classes
CS 638 Web Programming – Estan & Kivolowitz CS 638 Web Programming – Estan & Kivolowitz
C# replaces the implements and extends C# allows passing by reference and output parameters for
keywords with : both value and reference types
C# refers to the base class as base, not super Boolean variables are of type bool, not boolean
CS 638 Web Programming – Estan & Kivolowitz CS 638 Web Programming – Estan & Kivolowitz
CS 638 Web Programming – Estan & Kivolowitz CS 638 Web Programming – Estan & Kivolowitz