[Mono-list] Problems with CopyTo, using Contains(...) and inserting a character from one string into another.

PFJ pjohnson1 at uclan.ac.uk
Tue Jan 27 06:53:58 EST 2009


Hi,

I'm trying to copy a specific section of a string to another string.
My code looks like this

void search(string s)
string newstring;
for (int a = 0 ; a < s.Length; ++a)
{
 if (a + 1 > s.Length)
   continue;
 if (s[a + 1] < 'a')
   s.CopyTo(a, newstring.ToCharArray(), 0, 1);
 else
 {
   s.CopyTo(a, newstring.ToCharArray(),0, 2);
   a++;
 }
}

However, I'm getting an exception out of range error - even if a = 0.
If I replace newstring.ToCharArray with a true char array, I get the
same error.

Have I misunderstood copyto? It looks ok according to MSDN.

Another niggle, is there anyway to make something akin to Contains but
compares not just the first character, but for all given characters
(for example, my string contains BaSO4, if I use Contains, then B gets
seen first from the comparison list, it exits, which means that as e
doesn't exist and the code fails)? I've tried

if (System.Text.RegularExpressions.Regex.IsMatch(dupeform, element,
System.Text.RegularExpressions.RegexOptions.IgnoreCase))
and not to ignore the case, but that fails too.

Help!

TTFN

Paul
-- 
View this message in context: http://www.nabble.com/Problems-with-CopyTo%2C-using-Contains%28...%29-and-inserting-a-character-from-one-string-into-another.-tp21683670p21683670.html
Sent from the Mono - General mailing list archive at Nabble.com.



More information about the Mono-list mailing list