Using Regex/Match to find decimal Index location from RightToLeft.

I am trying to find the decimal index location from RightToLeft using Regex/Match. When the code below runs, I keep getting the index value from LeftToRight even though I specifiedRegexOptions.RightToLeft. What am I missing here?

Regex r =newRegex(@"[.]",RegexOptions.RightToLeft);
Match m = r.Match(tbMainInput.Text);
if (m.Success)
{
m.Index.ToString();
}

Thanks for your help...

[951 byte] By [rayfusion] at [2008-2-21]
# 1

sorry if this is not exactly what you wanted however wanted to suggest perhaps using the IndexOf('.') to obtain your decimal index?

string theString = "abc.123";

int theIndexOfDecimalPoint = theString.IndexOf('.');

will report the first occurance of the decimal point found in the string

Going back to the Regex portion - what does the original string look like?

ahmedilyas at 2007-8-31 > top of Msdn Tech,.NET Development,Regular Expressions...
# 2

The string that I am searching will contain a numbers like 123.45 or 123.4567. So.. I need to grab the decimal index going from right to left. The IndexOf is still giving me index from left to right.

Thanks for your fast response..

rayfusion at 2007-8-31 > top of Msdn Tech,.NET Development,Regular Expressions...
# 3
Try LastIndexof....
cablehead at 2007-8-31 > top of Msdn Tech,.NET Development,Regular Expressions...
# 4

that still wouldn't work as it would return the last index it found of the decimal point, which is not what is required apperently, but needing to find the position going FROM right To left, not the default left to right :-)

...just to add, is there any specific reason you need it from right to left?

A bad workaround would be to count from the right to left, going backwards, and checking the current character to see if its a period

ahmedilyas at 2007-8-31 > top of Msdn Tech,.NET Development,Regular Expressions...
# 5

string test = "123.4561";

test = test.Substring(test.LastIndexOf(".") + 1);

int index = test.Length;

Console.WriteLine(index);

cablehead at 2007-8-31 > top of Msdn Tech,.NET Development,Regular Expressions...
# 6

removed...correct answer above..

rayfusion at 2007-8-31 > top of Msdn Tech,.NET Development,Regular Expressions...
# 7
Why would you want to add an extra line of code?
cablehead at 2007-8-31 > top of Msdn Tech,.NET Development,Regular Expressions...
# 8

cablehead wrote:
Why would you want to add an extra line of code?

You are absolutely correct. I posted the my last post prior to seeing your solution.

Thanks cablehead :)

rayfusion at 2007-8-31 > top of Msdn Tech,.NET Development,Regular Expressions...
# 9

Or :

string test = "1.12";

int index = test.Substring(test.LastIndexOf(".") + 1).ToString().Length;

Console.WriteLine(index);

cablehead at 2007-8-31 > top of Msdn Tech,.NET Development,Regular Expressions...

.NET Development

Site Classified