0

For example, TOMILA RELEASE V6.24 , i want to get 6.24 i used

 if (txt.Contains("<TOMILA RELEASE")) 
 {
     int iStartIndex = txt.LastIndexOf("<TOMILA RELEASE") + 17;
     for (int i = 0; i < 50; i++) {
         if (txt[iStartIndex + i] == '>') break;
         currentRelease += txt[iStartIndex + i];

     }
 }

So, my question is if i want to get the specific 6 from TOMILA RELEASE V6.24, how could i get it?

3 Answers 3

2

You can try LastIndexOf followed by Substring

var result = str.Substring(str.LastIndexOf('TOMILA RELEASE V') + 1);
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to take first number in the string you can use following regular expression.

string s = "TOMILA RELEASE V6.24";
string digit = Regex.Match(s, "\\d").Value;

Here \d is for matching the digit, you can find more about regular expression in this tutorial, The 30 Minute Regex Tutorial

If you want to extract all number before dot then you can add + with \d and use do to end the extraction.

string number = Regex.Match(s, "\\d+.").Value.Replace(".","");

2 Comments

What does "\\d" means?
\d is for matching the digit, the tutorial will help you understand, codeproject.com/Articles/9099/The-Minute-Regex-Tutorial
0

If you want to get a specific portion of a string, you could use the below code

  string str = "6.24";
  var val = str.Substring(0, 1);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.