[Mono-list] ToTitleCase

Rob Brown-Bayliss rob@disengaged.co.nz
Thu, 14 Oct 2004 16:56:46 +1300


--=-X2jqNi9VQgCzCJK0IdIm
Content-Type: text/plain
Content-Transfer-Encoding: 7bit


Hi all, I am trying to capitalize the first letter of every word in a
string.  I would expect  this:


string test = StringUtils.CorrectName("this is a test");
Console.WriteLine(test);


to output:


This Is A Test


but I get:


This is a test


Here is the code I am using, is this a bug in the mono implementation or
the correct behaviour and a bug in my understanding?


	public class StringUtils 
	{
	
		static CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
		static TextInfo textInfo = cultureInfo.TextInfo;
		
		public static string CorrectName(string name)
		{
			name = name.ToLower();
			if (name.StartsWith("the "))
			{
				name = name.Remove(0,4);
				name = name + ", the";
			}
			
			return textInfo.ToTitleCase(name);
		}


--
Rob Brown-Bayliss

____________________________________
The liar's punishment is not in the
least that he is not believed, but
that he cannot believe anyone else.
____________________________________


--=-X2jqNi9VQgCzCJK0IdIm
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.2.1">
</HEAD>
<BODY>
<BR>
Hi all, I am trying to capitalize the first letter of every word in a string.&nbsp; I would expect&nbsp; this:<BR>
<BR>
<PRE>
string test = StringUtils.CorrectName(&quot;this is a test&quot;);
Console.WriteLine(test);

</PRE>
to output:
<PRE>

This Is A Test

</PRE>
but I get:
<PRE>

This is a test

</PRE>
Here is the code I am using, is this a bug in the mono implementation or the correct behaviour and a bug in my understanding?<BR>
<BR>
<PRE>
	public class StringUtils 
	{
	
		static CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
		static TextInfo textInfo = cultureInfo.TextInfo;
		
		public static string CorrectName(string name)
		{
			name = name.ToLower();
			if (name.StartsWith(&quot;the &quot;))
			{
				name = name.Remove(0,4);
				name = name + &quot;, the&quot;;
			}
			
			return textInfo.ToTitleCase(name);
		}
</PRE>
<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
--<BR>
<TABLE>
<TR>
<TD>
<B>Rob Brown-Bayliss</B>
</TD>
</TR>
<TR>
<TD>

<HR>
<BR>
The liar's punishment is not in the least that he is not believed, but that he cannot believe anyone else.
<HR>

</TD>
<TD>
<BR>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>

--=-X2jqNi9VQgCzCJK0IdIm--