java - Equivalent of matcher.start and matcher.end in c# -
i new c# , trying convert below code c# can not find api in c# so.
- please explain equivalent of matcher.start() , matcher.end().
what equivalent of matcher.group() in c#.
private string getfinalvariant(string strinputword) { pattern pat = pattern.compile("[aeiouhy]+"); matcher mat = pat.matcher(strinputword); int lenghtofinputword = strinputword.length(); while (mat.find()) { if (mat.start() == 0) { int index = '1'; map<string, string> temp = rulelist[index]; if (temp.containskey(mat.group())) { strinputword = strinputword.replacefirst(mat.group(), temp.get(mat.group())); } } else if (mat.end()== lenghtofinputword) { int index = '3'; int lastindex = strinputword.lastindexof(mat.group()); map<string, string> temp = rulelist[index]; if (temp.containskey(mat.group())) { string tail = strinputword.substring(lastindex).replacefirst(mat.group(), temp.get(mat.group())); strinputword = strinputword.substring(0, lastindex) + tail; } } else { int index = '2'; map<string, string> temp = rulelist[index]; string str = mat.group(); // system.out.println(str); // system.out.println(mat.start()); if (temp.containskey(mat.group())) { if (strinputword.length() > 3) { int index1 = strinputword.indexof(mat.group(), 1); if (index1 != 0 && index1 != strinputword.length() - 1) { string matched = strinputword.substring(index1, strinputword.length() - 1).replacefirst(mat.group(), temp.get(mat.group())); strinputword = strinputword.substring(0, index1) + matched + strinputword.charat(strinputword.length() - 1); } } else if (strinputword.length() == 3) { strinputword = strinputword.charat(0) + strinputword.substring(1, 2).replacefirst(mat.group(), temp.get(mat.group())) + strinputword.charat(strinputword.length() - 1); } } } } return strinputword; }
you can use
var matches = regex.matches(yourstring);
this return matches. each match object of type match, has index property can use work out first , last match.
for group() can use same collection iterate through different matches.
Comments
Post a Comment