troubleshooting Question

How to rename duplicated strings in C#

Avatar of Skale
Skale asked on
C#
2 Comments1 Solution75 ViewsLast Modified:
Hello,

I'm using below code for getting some strings from excel sheet to use them in another worksheet's table as column headers, but some of strings has duplicated and i'd like to change their naming adding suffix _1, _2, ... , _n

  //Read Parameter Naming
  IEnumerable<ClosedXML.Excel.IXLCell> descList = wsRef.Column(1).CellsUsed().Skip(2).Where(c => !string.IsNullOrWhiteSpace(c.CellRight().Value.ToString()));
  i = 3;
  //Write Table Headers to Sheet
  foreach (ClosedXML.Excel.IXLCell desc in descList) { ws.Cell(1, i).Value = desc.CellRight().Value; i += 1; }

And this is my table column headers;

General
Extrusion by
Contour profile
Input by
SU2 file
Interpolation
Approximation parameter
Extrusion axis
Depth
Cross section
Input by
SU2 file
Input Function
Material side

Now as you can see some of them duplicated values and i'd like to change namings like below;

General
Extrusion by
Contour profile
Input by
SU2 file
Interpolation
Approximation parameter
Extrusion axis
Depth
Cross section
Input by_1
SU2 file_1
Input Function
Material side

Any help would be grateful. Thank you.
ASKER CERTIFIED SOLUTION
it_saige
Developer
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros