Good afternoon,
I have been working on a simple problem for a long time because I am really not sure how to approach it.
I need a user to type in a sentence at a command prompt, after that I trim the String and place it into an array to make it all lower case but the first letter of that sentence, that is why I take the String^ and place it into the array, I thought it would be the cleanest approach.
Example of the command prompt result needed.
The user types:
this IS a TEST
Once processed the output should be:
This is a test
My code:
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
// User input
Console::WriteLine(L"Please enter a sentence: ");
String ^ userSentence;
userSentence = Console::ReadLine();
//Triming
Console::WriteLine();
String^ newStr = userSentence->Trim();
Console::WriteLine("Sentence trimmed applied:");
Console::WriteLine(newStr);
//array section
array<String^>^ data;
data = gcnew array<String^>{newStr};
Console::WriteLine("from array:");
//loop through each character and make it lower-case.
int i =0;
for(int i = 0; data[i] != '\0'; i++)
{
data[i]->ToLower(data[i]);
}
data[0]->ToUpper(data[0]);
Console::WriteLine(data);
return 0;
}
However things don't workout the way I would hope and I get this error message on line 24:
error C2446: '!=' : no conversion from 'int' to 'System:: String ^'
I see that my data array content is trying to be used as an "int" but I don't how to fix this?
I would greatly appreciate your help.
John