c# - What is the most elegant way to implement GetTextAfterMarker() -


I have one more old work from my C # 1 day, what would be one more great way to write this:

  // Method: Text goes into a string in front of a marker, if the marker is not there, then return the empty string / example: GetTextAfterMarker ("documents / jan / letter043.doc" GiftTextAfterMarker ("letter043.doc", "/") / / rank: 8 public static string GetTextAfterMarker (string line, string marker) It is {string r = ""; Int pos = line.IndexOf (marker); If (pos! = -1) {r = line.Substring (pos + (marker.Length), line.Length-pos- (marker.Length)); } Other {r = ""; } Return R; }  

I've got some strange names, given that the text should be shown First marker but it works the same, I think (I have taken the liberty to change the name):

  public stable string GetTextBeforeMarker (string line, String marker) {if (line == empty) {fix minimum to new logic ("line"); } If (marker == faucet) {new logic: NullException ("marker"); } String result = line.Split (new string [] {marker}, string split option. A) [0]; Return line Excel (result)? String Empty: Results; }  

Explanation: Divide the string into an array as a segment of the marker, if the first element of the result is the same as the input, the marker was not in the string, so we have an empty string Return, otherwise we return the first element (which is the text of the first event of the marker).


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 -