c# - string.equals giving false positives -


this question has answer here:

in storing events event management system, storing history of changes. because project specifies use of mysql, , mysql triggers leave desired, using actual code detect changes. have following line of code see if support notes field changed, , add history record accordingly:

    ....     if (!string.equals(oldeventinfo.supportnotes, neweventinfo.supportnotes))     {  changesmade.add(new eventhistorydataitem("support notes", oldeventinfo.supportnotes, neweventinfo.supportnotes)); }     ....     eventsdataset eds = new eventsdataset();     eventsdatasettableadapters.eventhistorytableadapter ehta = new eventsdatasettableadapters.eventhistorytableadapter();     eventsdatasettableadapters.eventhistorydatatableadapter ehdta = new eventsdatasettableadapters.eventhistorydatatableadapter();     int64 historyid = convert.toint64(ehta.insertquery(neweventinfo.id.value, datetime.now, userid));      eds.eventhistorydata.clear();     foreach (eventhistorydataitem thischange in changesmade)     {         eventsdataset.eventhistorydatarow newrow = (eventsdataset.eventhistorydatarow)eds.eventhistorydata.newrow();         newrow.eventhistoryid = historyid;         newrow.field = thischange.field;         newrow.oldvalue = thischange.oldvalue;         newrow.newvalue = thischange.newvalue;         eds.eventhistorydata.addeventhistorydatarow(newrow);     }     ehdta.update(eds.eventhistorydata); 

the problem getting history records "support notes" identical values in before , after. i've looked @ other questions on string.equals generating false returns, , have checked make sure before , after strings identical, , are. there no spaces or carriage returns or newlines. binary identical.

so, gives? how record ending in history says value has changed b, , b being identical?

it's because string encoding different , strings not equal, although contain same characters.

if want compare 2 strings , different sources, , you're not worried encoding, compare them using string.normalize() method , work.


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -