Skip to Main Content
C# 10.0 All-in-One For Dummies
book

C# 10.0 All-in-One For Dummies

by John Paul Mueller
March 2022
Intermediate to advanced content levelIntermediate to advanced
864 pages
19h 46m
English
For Dummies
Content preview from C# 10.0 All-in-One For Dummies

Chapter 3

Pulling Strings

IN THIS CHAPTER

Bullet Pulling and twisting a string with C#

Bullet Matching searching, trimming, splitting, and concatenating strings

Bullet Parsing strings read into the program

Bullet Formatting output strings manually or using String.Format()

For many applications, you can treat a string like one of the built-in value-type variable types such as int or char. Certain operations that are otherwise reserved for these intrinsic types are available to strings:

int i = 1; // Declare and initialize an int.string s = "abc"; // Declare and initialize a string.

In other respects, as shown in the following example, a string is treated like a user-defined class (Book 2 discusses classes):

string s1 = new String();string s2 = "abcd";int lengthOfString = s2.Length;

Which is it — a value type or a class? In fact, String is a class for which C# offers special treatment because strings are so widely used in programs. The keyword string is an alias of the String class, as shown in this bit of code:

String s1 = "abcd"; // Assign a string literal to a String obj.string s2 = s1; // Assign a String ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Joe Mayo
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 9781119839071Purchase Link