Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
C# Trim end of string by pattern

I want to trim the end of a series of strings to remove a suffix which follows a pattern.

In the following examples, I want to trim the Vx suffix at the end.

The numerical part could be any number of digits.

Example strings

AbcV1
BcdV12
TuvV32
VwxV42

Output

Abc
Bcd
Tuv
Vwx

How could I implement such a logic in C#? Is there a regex/pattern based way to use .TrimEnd()?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

So you want any V with digits after that removed. This would do it.

public static void Main()
{
   string[] arr = { "AbcV1", "BcdV12", "TuvV32", "VwxV42" };
    
    foreach (string a in arr)
      Console.WriteLine(System.Text.RegularExpressions.Regex.Replace(a, "V[0-9]+$", ""));
    
}

or

"V[\d]+$"

whatever you prefer.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!