We help IT Professionals succeed at work.
Get Started

How to rename duplicated strings in C#

Hakan
Hakan asked
on
69 Views
Last Modified: 2020-02-04
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; }

Open in new window


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.
Comment
Watch Question
Developer
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE