using toupper to uppercase an array index
-
I'm trying to uppercase the second word in a string of two words (a first and last name).
int index;
string name = "Jeffrey steinberg";index = name.IndexOf(' ');
name = name[index + 1].ToUpper();The toupper function isn't working though. How would I uppercase just the s in steinberg?
-
I'm trying to uppercase the second word in a string of two words (a first and last name).
int index;
string name = "Jeffrey steinberg";index = name.IndexOf(' ');
name = name[index + 1].ToUpper();The toupper function isn't working though. How would I uppercase just the s in steinberg?
Here's the method I use:
/// <summary>
/// Convert the clipboard text to proper English capitalisation.
/// If Control is down, use Title Case
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void butLowerCase_Click(object sender, EventArgs e)
{
bool sentenceCase = (ModifierKeys & Keys.Control) != Keys.Control;
if (Clipboard.ContainsText())
{
string s = Clipboard.GetText();
string[] lines = s.Split('\n');
StringBuilder sb = new StringBuilder();
string EOL = "";
for (int i = 0; i < lines.Length; i++)
{
sb.Append(EOL);
if (lines[i].Length > 1)
{
if (sentenceCase)
{
sb.Append(lines[i].Substring(0, 1).ToUpper());
sb.Append(lines[i].Substring(1).ToLower());
}
else
{
// Title Case
string[] words = lines[i].ToLower().Split(' ');
string sep = "";
foreach (string word in words)
{
if (word.Length > 0)
{
if (conjunctions.Contains(word))
{
sb.AppendFormat("{0}{1}", sep, word);
}
else
{
sb.AppendFormat("{0}{1}{2}", sep, word.Substring(0, 1).ToUpper(), word.Length > 1 ? word.Substring(1).ToLower() : "");
}
sep = " ";
}
}
}
}
else
{
sb.Append(lines[i]);
}
EOL = "\n";
}
Clipboard.SetText(sb.ToString());
}
}Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
I'm trying to uppercase the second word in a string of two words (a first and last name).
int index;
string name = "Jeffrey steinberg";index = name.IndexOf(' ');
name = name[index + 1].ToUpper();The toupper function isn't working though. How would I uppercase just the s in steinberg?
-
Here's the method I use:
/// <summary>
/// Convert the clipboard text to proper English capitalisation.
/// If Control is down, use Title Case
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void butLowerCase_Click(object sender, EventArgs e)
{
bool sentenceCase = (ModifierKeys & Keys.Control) != Keys.Control;
if (Clipboard.ContainsText())
{
string s = Clipboard.GetText();
string[] lines = s.Split('\n');
StringBuilder sb = new StringBuilder();
string EOL = "";
for (int i = 0; i < lines.Length; i++)
{
sb.Append(EOL);
if (lines[i].Length > 1)
{
if (sentenceCase)
{
sb.Append(lines[i].Substring(0, 1).ToUpper());
sb.Append(lines[i].Substring(1).ToLower());
}
else
{
// Title Case
string[] words = lines[i].ToLower().Split(' ');
string sep = "";
foreach (string word in words)
{
if (word.Length > 0)
{
if (conjunctions.Contains(word))
{
sb.AppendFormat("{0}{1}", sep, word);
}
else
{
sb.AppendFormat("{0}{1}{2}", sep, word.Substring(0, 1).ToUpper(), word.Length > 1 ? word.Substring(1).ToLower() : "");
}
sep = " ";
}
}
}
}
else
{
sb.Append(lines[i]);
}
EOL = "\n";
}
Clipboard.SetText(sb.ToString());
}
}Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
I also have something similar, except along with conjunctions, I skip articles and prepositions as well.
You have just been Sharapova'd.
-
I'm trying to uppercase the second word in a string of two words (a first and last name).
int index;
string name = "Jeffrey steinberg";index = name.IndexOf(' ');
name = name[index + 1].ToUpper();The toupper function isn't working though. How would I uppercase just the s in steinberg?
You can use the inbuilt library mathod ToTitleCase() as
string name = "Jeffrey steinberg";
TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
name = textInfo.ToTitleCase(name);For detail to use library method go to - https://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx[^]
Pankaj Maurya Sr. Software Engineer Gurgaon, India