As I get all the Codes and Description from the database I am storing them in the List. But a few of the Descriptions have a second entry with the same Code to continue the Desciption that does not fit in the first entry field. So I add it to the Description and want to overwrite the List item. Just doing an Add does not do it. So I thought that if I find the index with IndexOf and do a RemoveAt and then do an Add again it would do it and it does not abort, but does not store anything.
Here is the code.
VB.NET
reasonList.IndexOf(myReason, indx);
reasonList.RemoveAt(indx);
reasonList.Add(new ReasonRecord(dataRowItem["Code"].ToString(), myReasonDesc));
myReasonDesc is the Description that adds the second Description to the first Description.
Say the first Description is "CLAIM WAS PAID UNDER THE NATIONAL PREFERRED" and
the second is " PROVIDER NETWORK". I now want to store the
"CLAIM WAS PAID UNDER THE NATIONAL PREFERRED PROVIDER NETWORK"
How can I do this?
Thanks for any help.
arep
Javeed M ShaikhRank #839 · 2.7K reputationPosted Oct 4, 2011, 12:18 PM EDT
reasonList.IndexOf(myReason, indx); --> Search for code from the index and below.
reasonList.RemoveAt(indx); --> Assuming the code is found and you remove that entry.
reasonList.Add(new ReasonRecord(dataRowItem["Code"].ToString(), myReasonDesc)); --> You add to the end of the list the code and the concatenated desc.
so is the last line not adding anything, please provide more code snippet to understand better.
Please do not forget to mark "Accepted Answer".
A RepaskyRank #8,108 · 228 reputationPosted Oct 4, 2011, 12:52 PM EDT
I changed the code slightly. I found out the Add is working, but the Remove is not. So when I am searching later on for the Code, it find the first one and not the second. I only want to save one occurence. So here is the code. Thanks, arep DetailRecord detailRec = new DetailRecord(); string sCode = ""; ReasonRecord myReason = new ReasonRecord(); foreach (DataRow dataRowItem in dt.Rows) { //Add Description and save, if code is the same foreach (ReasonRecord myReasonItem in reasonList) { if (myReasonItem.Code == (string)dataRowItem["Code"]) { myReason.Code = myReasonItem.Code; myReason.Description = myReasonItem.Description + " " + dataRowItem["Description"]; } } //Save reason code if (sCode == dataRowItem["Code"].ToString()) { reasonList.Remove(myReason); reasonList.Add(new ReasonRecord(dataRowItem["Code"].ToString(), myReason.Description)); } else { reasonList.Add(new ReasonRecord(dataRowItem["Code"].ToString(), dataRowItem["Description"].ToString())); } sCode = dataRowItem["Code"].ToString(); }A RepaskyRank #8,108 · 228 reputationPosted Oct 4, 2011, 12:58 PM EDT
arep
Javeed M ShaikhRank #839 · 2.7K reputationPosted Oct 4, 2011, 1:18 PM EDT
You have a set of Rows with Duplicate Codes and also another set of record in List with Duplicate code. you want to merge the description from both these and create a new list with unique Codes and merged descriptions, is that correct?
VulpesRank #55 · 29.2K reputationPosted Oct 4, 2011, 2:14 PM EDT
A RepaskyRank #8,108 · 228 reputationPosted Oct 4, 2011, 6:07 PM EDT
arep
VulpesRank #55 · 29.2K reputationPosted Oct 5, 2011, 1:20 AM EDT
I'd suggest the non-breaking space (Unicode 160) or (HTML) which shouldn't occur in ordinary text but looks like a space when displayed.
So you'd need to replace this line:
myReasonItem.Description += " " + dataRowItem["Description"];
with
myReasonItem.Description += " \xA0" + dataRowItem["Description"];
You can then recover the two parts with:
string[] items = myReasonItem.Description.Split('\xA0');
// items[0] is first part and items[1] is second part
A RepaskyRank #8,108 · 228 reputationPosted Oct 5, 2011, 8:00 AM EDT
public static string LookUpReason(string sCode) { string functionReturnValue = null; //foreach (ReasonRecord item in reasonList) for (int i = reasonList.Count - 1; i > 0; i--) { if (sCode.Substring(0, 2) == reasonList[i].Code) { functionReturnValue = reasonList[i].Description; return functionReturnValue; } } functionReturnValue = ""; return functionReturnValue; } Thanks for the help. arepSuthish NairRank #92 · 22.8K reputationPosted Oct 5, 2011, 10:27 AM EDT
http://stackoverflow.com/questions/194852/concatenate-many-rows-into-a-single-text-string