Posted By

krisdb on 05/14/09


Tagged

c-sharp


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

rtipton
umang_nine


GetValueBetweenTwoValues


 / Published in: C#
 

  1. private string GetValueBetweenTwoValues(string str, string startVar, string endVar)
  2. {
  3. string output = String.Empty;
  4.  
  5. Match match = Regex.Match(str, String.Format("{0}(.*){1}", startVar, endVar));
  6.  
  7. if (match.Success)
  8. output = match.Groups[1].Value;
  9.  
  10. return output;
  11. }
  12.  
  13.  
  14. private string GetValue(string text, string startVal, string endVal)
  15. {
  16. string output = String.Empty;
  17.  
  18. int length = text.Length;
  19. int start = text.IndexOf(startVal);
  20.  
  21. if (start > -1)
  22. {
  23. int end = text.IndexOf(endVal, start);
  24.  
  25. if (end > -1)
  26. {
  27. int contentLength = (end - start);
  28.  
  29. output = text.Substring(start + (startVal.Length), contentLength - (startVal.Length));
  30. }
  31. }
  32.  
  33. return output;
  34. }

Report this snippet  

You need to login to post a comment.