string - How can I refactor this C# code using Split()? -


How can I refact this so that it does not declare number of items as a variable Will it?

  // Method: Text is found in a string in front of a marker, if the marker is not there, then return the empty string / example: GetTextAfterMarker ("documents / jan / letter043.doc" , "/") "Letter043.doc" / Example: GetTextAfterMarker ("letter043.doc", "/") / Example: GetTextAfterMarker ("letter043.doc", ".") "Doctor" public Fixed string GetTextAfterMarker (string line, string marker) {int numberoffiths = line. Split (new string [] {marker}, string split option .one) .count (); String result = line. Split (new string [] {marker}, string split option. A) [number 1-1]; Return line Excel (result)? String Empty: Results; } 

If you are using 3.5 then it is trivial with Linq:

  Public Static String GetTextAfterMarker2 (string line, string marker) {string result = line.Split (new string [] {marker}, StringSplitOptions.None). Previous (); Return line Excel (result)? String Empty: Results; }  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -