c# - Get Substring - everything before certain char -


I am trying to figure out the best way to get everything before the character in the string. Some example strings are below string length before - varies and can be any length

  223232-1.jpg 443-2.jpg 34443553-5.jpg  

I need a value that is just right before the start index of 0 - then substrings will be 223232, 443 and 34443553.

  class program {static or oid key (string [] ARGs) {console. Weblines ("223232-1.jpg" .GetUntilOrEmpty ()); Console.WriteLine ("443-2.jpg" .GetUntilOrEmpty ()); Console.WriteLine ("34443553-5.jpg" .GetUntilOrEmpty ()); Console.ReadKey (); }} Fixed class helper {public static string GetUntilOrEmpty (this string text, string stoppage = "-") {if String.IsNullOhhiteSpace (text) {int charLocation = text.IndexOf (stopAt, StringComparison.Ordinal); If (charLocation & gt; 0) {Return Text. Substrings (0, four places); }} Return string. Api; }}  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -