Question: I have this code:

```
string firstTag = "Forums2008/forumPage.aspx?forumId=";
string endTag = "</a>";
index = forums.IndexOf(firstTag, index1);

if (index == -1)
   continue;

var secondIndex = forums.IndexOf(endTag, index);

result = forums.Substring(index + firstTag.Length + 12, secondIndex - (index + firstTag.Length - 50));

```

The string i want to extract from is for example:

```
<a href="/Forums2008/forumPage.aspx?forumId=317" title="הנקה">הנקה</a>

```

What i want to get is the word after the title only this: `הנקה`
And the second problem is that when i'm extracting it i see instead hebrew some gibrish like this: ������

Answer: 
One powerful way to do this is to use [Regular Expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) instead of trying to find a starting position and use a substring. Try out this code, and you'll see that it extracts the anchor tag's title:

```
    var input = "<a href=\"/Forums2008/forumPage.aspx?forumId=317\" title=\"הנקה\">הנקה</a>";

    var expression = new System.Text.RegularExpressions.Regex(@"title=\""([^\""]+)\""");

    var match = expression.Match(input);

    if (match.Success) {
        Console.WriteLine(match.Groups[1]);
    }
    else {
        Console.WriteLine("not found");
    }       

```

And for the curious, here is a version in JavaScript:

```js
var input = '<a href="/Forums2008/forumPage.aspx?forumId=317" title="הנקה">הנקה</a>';

var expression = new RegExp('title=\"([^\"]+)\"');

var results = expression.exec(input);

if (results) {
    document.write(results[1]);
  }
else {
  document.write("not found");
}
```
Okay here is the solution using `String.Substring()` `String.Split()` and `String.IndexOf()`

```
    String str = "<a href=\"/Forums2008/forumPage.aspx?forumId=317\" title=\"הנקה\">הנקה</a>"; // <== Assume this is passing string. Yes unusual scape sequence are added 

    int splitStart = str.IndexOf("title=");  // < Where to start splitting
    int splitEnd = str.LastIndexOf("</a>");  // < = Where to end

    /* What we try to extract is this :  title="הנקה">הנקה
     *  (Given without escape sequence)
     */

    String extracted = str.Substring(splitStart, splitEnd - splitStart); // <=Extracting required portion 

    String[] splitted = extracted.Split('"'); // < = Now split with "

    Console.WriteLine(splitted[1]);  // <= Try to Out but yes will produce ???? But put a breakpoint here and check the values in split array 

```

Now the problem, here you can see that i have to use escape sequence in an unusual way. You may ignore that since you are simply passing the scanning string.

And this actually works, but you cannot visualize it with the provided `Console.WriteLine(splitted[1]);`

**But** if you put a break point and check the extracted split array you can see that text are extracted. you can confirm it with following screenshot

![Debugging for extracted text](https://i.stack.imgur.com/7seHD.png)