c# - string.equals giving false positives -
this question has answer here:
- why string.equals returning false? 3 answers
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
Post a Comment