I am passing a message from a server that gets stored into a string variable called strObject. I wish to convert the string inside strObject to upper case. So, I use ToUpper
strObject.ToUpper()
returns a string
in upper case
Use the following ...
strObject = strObject.ToUpper().Trim();
Your method inserts values to your strObject and strValue variables to which you call various worker methods but those worker methods do not change the immutable string variables that have already been created.
Although the original variables are immutable you can still set new variables (Even with the same name) equal to the original plus the result of the worker method.
So all you really need to do is to change
strObject.ToUpper().Trim();
and
strValue.ToUpper().Trim();
to
strObject = strObject.ToUpper().Trim()
and
strValue = strvalue.ToUpper().Trim()
This answer is pretty much a duplicate of my answer here but I think both are correct.
string.ToUpper()
returns a value, use it.
Strings are immutable, so calling the functions on the string doesn't actually change the strings. Instead they return a modified copy of the strings.
This means that you have to store the returned value of the functions, fore example in the original variable.
A System.String
is immutable, so you must re-assign, like:
strObject = strObject.ToUpper().Trim();
All methods that manipulate strings, leave the original string unchanged and returns a new string with the desired content. You must pick up that return value and assign it to something.
This won't work since strings are immutable, you have to assign the value back to strObject
strObject = strObject.ToUpper().Trim();
Also there is nothing much done by the switch
as shown in your code, you can remove it unless this is not the entire code.
public void VerifyValue(String strObject, String strValue, int row)
{
//strObject.ToUpper().Trim();
//strValue.ToUpper().Trim();
if(strObject.ToUpper() == "TASK_STATUS")
{
if (m_taskStatus.taskStatus.ToString() == strValue.ToUpper())
{
ExcelRecorder(null, row);
}
else
{
ExcelRecorder("The value [" + m_taskStatus.taskStatus.ToString() + "] does not match with the given value.", row);
}
}
}