Learning C# 3.0 by MacDonald Brian Liberty Jesse & Brian MacDonald
Author:MacDonald, Brian, Liberty, Jesse & Brian MacDonald [Jesse Liberty]
Language: eng
Format: epub
Tags: COMPUTERS / Programming Languages / C#
ISBN: 9780596554200
Publisher: O'Reilly Media
Published: 2008-11-17T16:00:00+00:00
The output looks like this:
s5 copied from s2: ABCD String s3 is 94 characters long. The 5th character is r s3:Liberty Associates, Inc. provides custom .NET development, on-site Training and Consulting Ends with Training?: False Ends with Consulting?: True The first occurrence of Training in s3 is 71 s10: Liberty Associates, Inc. provides custom .NET development, on-site excellent Training and Consulting s11: Liberty Associates, Inc. provides custom .NET development, on-site excellent Training and Consulting
The Length property returns the length of the entire string, and the index operator ([]) is used to access a particular character within a string. Just like arrays, the index numbering in a string starts at zero.
Console.WriteLine( "\nString s3 is {0} characters long. ", s5.Length); Console.WriteLine( "The 5th character is {0}\n", s3[4]);
Here's the output:
String s3 is 4 characters long. The 5th character is r
The EndsWith( ) method asks a string whether a substring is found at the end of the string. Thus, you might first ask whether s3 ends with the word Training (which it does not), and then whether it ends with the word Consulting (which it does):
Console.WriteLine("s3:{0}\nEnds with Training?: {1}\n", s3, s3.EndsWith("Training") ); Console.WriteLine( "Ends with Consulting?: {0}", s3.EndsWith("Consulting"));
The output reflects that the first test fails and the second succeeds:
Ends with Training?: False Ends with Consulting?: True
The IndexOf( ) method locates a substring within a string, and the Insert( ) method inserts a new substring into a copy of the original string. The following code locates the first occurrence of Training in s3:
Console.WriteLine("\nThe first occurrence of Training "); Console.WriteLine ("in s3 is {0}\n", s3.IndexOf("Training"));
The output indicates that the offset is 71:
The first occurrence of Training in s3 is 71
Then use that value to insert the word excellent, followed by a space, into that string.
Actually, the insertion is into a copy of the string returned by the Insert( ) method and assigned to s10:
string s10 = s3.Insert(71,"excellent "); Console.WriteLine("s10: {0}\n",s10);
Here's the output:
s10: Liberty Associates, Inc. provides custom .NET development, on-site excellent Training and Consulting
Finally, you can combine these operations to make a more efficient insertion statement:
string s11 = s3.Insert(s3.IndexOf("Training"),"excellent "); Console.WriteLine("s11: {0}\n",s11);
with the identical result:
s11: Liberty Associates, Inc. provides custom .NET development, on-site excellent Training and Consulting
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(12593)
Hello! Python by Anthony Briggs(9928)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9804)
The Mikado Method by Ola Ellnestam Daniel Brolund(9787)
Dependency Injection in .NET by Mark Seemann(9348)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8310)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7773)
Grails in Action by Glen Smith Peter Ledbrook(7705)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7568)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7192)
Microservices with Go by Alexander Shuiskov(6955)
Practical Design Patterns for Java Developers by Miroslav Wengner(6872)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6816)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6426)
Angular Projects - Third Edition by Aristeidis Bampakos(6235)
The Art of Crafting User Stories by The Art of Crafting User Stories(5750)
NetSuite for Consultants - Second Edition by Peter Ries(5676)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5492)
Kotlin in Action by Dmitry Jemerov(5076)
