Languages
[Edit]
EN

C# / .NET - remove last 2 characters from string

0 points
Created by:
Trenton-McKinney
618

In this article, we would like to show you how to remove the last 2 characters from the string in C# / .NET.

Quick solution:

 

Practical examples

Edit

1. Using String Substring() method

Edit

In this example, we use String Substring() method to create a new result substring from the text string without the last 2 characters.

Syntax:

Note:

If length is not given, substring will be done from startIndex to the end of the text.

Practical example:

Output:

2. Using index from end ^ and range operator ..

Edit

The range operator .. is used to make a slice of the collection.

Practical example:

Output:

3. Using String Remove() method

Edit

Syntax:

Practical example:

Output:

Reference

Edit
  1. Substring() method - .NET Docs
  2. Range operator - .NET Docs
  3. String.Remove Method - .NET Docs 
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

C# / .NET - String (popular problems)

C# / .NET - remove last 2 characters from string
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join