I cannot get the syntaxt to work on the string compare here. I don't know why I keep getting a message saying it's trying to conver an integer to abool in my String.Compare:
foreach (string excelDescription in exceldata)
{
using (ExcelWrapper xl = new ExcelWrapper(excelDescription))
{
success = true;
xl.SelectWorksheet(1,1,1);
host.Log(TraceLevel.Info, "Loaded Excel spreadsheet: " + excelDescription);
string lastAlbumTitle = string.Empty;
int AlbumCount = 1;
// set total # of records in spreadsheet
recTotal += xl.Rows - 1;
for (int row = 1; row < xl.Rows; ++row, host.PercentComplete = 10 + (row * 80 / xl.Rows))
{
string fileName = xl[row,4];
string fileExtW = ".wav";
string currentAlbumTitle = xl[row,1];
string filePathSourceW = host.GetConfigSetting(KEY_FS_SO_PrW
bool validStrucW = validateStruct(host, filePathSourceW, fileName, fileExtW);
if (String.Compare(lastAlbumTitle, currentAlbumTitle,true)) <<------- Error is here
{
AddNewProduct(xl, row, host, fileExtW, "A", filePathSourceW, fileName, moveFile, SID);
}
else...

String compa Cannot implicitly
TanLU
baskark
> 0 means left hand side is greater than right hand side (in alphabetical order)
0 means lhs == rhs
Daniel_Bowen
String.Compare(x,y,true) will do a case-insensitive comparison. Using String's "==" operator does a case-sensitive comparison.
Javfarary
thanks all...
what does doing a < 0 say or > 0 say
resnickaXXX
The problem is, it's now significantly slower than using string.Compare() because you are now creating two new strings and uppercasing them before comparing them, which is SIGNIFICANTLY slower than just using string.Compare().
The original use of string.Compare() was fine, there's no need to change it!
TwoSixTwo
or use
if (lastAlbumTitle == currentAlbumTitle)
or use
if (lastAlbumTitle.Equals(currentAlbumTitle))
I would avoid using .compare - this tells you which one is higher than the other alphabetically - it will return 0 if they are the same. This will be far worse computationally than the above functions.
Hope that helps:)
Ross
ashwin_k_s
The simple nmenonic to remember, given string A,B
String.Compare(A,B) == 0 is the same as A == B
String.Compare(A,B) < 0 is the same as A < B
String.Compare(A,B) > 0 is the same as A > B
Afzala
String.Compare returns an integer, not a boolean. What you need to do is change the error line from
if (String.Compare(lastAlbumTitle, currentAlbumTitle,true))
to
if (String.Compare(lastAlbumTitle, currentAlbumTitle,true) == 0)
That will solve your problem.
Kim Ohrns
Ah use this then:-
if (lastAlbumTitle.ToUpper() == currentAlbumTitle.ToUpper())
Enjoy:)
Ross