web analytics
Working with Strings in C# Options
codeling
Posted: Wednesday, June 21, 2017 2:56:26 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 777
Points: 3264

String.TrimEnd(Char[])

The following example demonstrates how you can use the TrimEnd(Char[]) method to trim white space or punctuation marks from the end of a string.

using System;

public class TrimEnd
{
   public static void Main()
   {
      string sentence = "The dog had a bone, a ball, and other toys.";
      char[] charsToTrim = {',', '.', ' '};
      string[] words = sentence.Split();
      foreach (string word in words)
         Console.WriteLine(word.TrimEnd(charsToTrim));
   }
}
// The example displays the following output:
//       The
//       dog
//       had
//       a
//       bone
//       a
//       ball
//       and
//       other
//       toys
Sponsor
Posted: Wednesday, June 21, 2017 2:56:26 PM
codeling
Posted: Tuesday, July 11, 2017 9:32:53 AM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 777
Points: 3264

Determine if all characters in a string are the same

I have a situation where I need to filter out any string line in a tex file where all the characters are the same. The follow C# code can be used to determine if all the characters are the same:

return (ssn.Distinct().Count() == 1)

Users browsing this topic
Guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.


© 2017 Digcode.com. All rights reserved.