Remove Integer at end of string in C#

on Oct 29, 2018 12:32 AM

Dear All, 

I have multiple lines like below, in which the number changes in each line:

string Line1=No Exceptions Noted Page 30

string Line2=No Exceptions Noted Page 31

I was able to remove the word Page, but also I want to remove the number at the end of each line. How can I do this with below code? Or any suggestions?

string[] data = Line1.Split(new string[] { "Page" }, StringSplitOptions.None);



Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Oct 29, 2018 12:42 AM

Hi dharmendr,

The exact output: No Exceptions Noted

I just found the answer:

var digits = new[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
var input = "No Exceptions Noted 30";
var result = input.TrimEnd(digits);

Output: No Exceptions Noted

Thanks for replying,


on Oct 29, 2018 12:46 AM

Refer below code.

string Line1 = "No Exceptions Noted Page 30";
Response.Write(Line1.Split(new string[] { "Page" }, StringSplitOptions.None)[0]);