Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-02-21 10:29 AM
Hi
Can anyone provide a code (C#), or give advise on, how to replace dot with comma (or other characters) for an entire column in a collection. I need to be able to define which column and I want to avoid looping.
Thank you!
Can anyone provide a code (C#), or give advise on, how to replace dot with comma (or other characters) for an entire column in a collection. I need to be able to define which column and I want to avoid looping.
Thank you!
Answered! Go to Answer.
1 BEST ANSWER
Helpful Answers
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-02-21 02:01 PM
Hi Karina,
Since you mentioned you want to be able to modify all rows for one specific column, this code should work.
foreach(DataRow row in inputCollection.Rows)
{
row[columnName] = row[columnName].ToString().Replace(".",",");
}
outputCollection = inputCollection;
Since you mentioned you want to be able to modify all rows for one specific column, this code should work.
foreach(DataRow row in inputCollection.Rows)
{
row[columnName] = row[columnName].ToString().Replace(".",",");
}
outputCollection = inputCollection;
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-02-21 06:22 PM
There should be an action in the stock Collection Manipulation object for Remove Dots From Headers that should help.
In case you don't have it, this is the VB code:
In case you don't have it, this is the VB code:
For Each Column As DataColumn In Input_Collection.Columns
Column.ColumnName=Microsoft.Visualbasic.Replace(Column.ColumnName,".","")
Next
Output_Collection = Input_Collection
And the C# version of it:
foreach (DataColumn col in Input_Collection.Columns) {
col.ColumnName = col.ColumnName.Replace(".", "");
}
Output_Collection = Input_Collection;
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-02-21 08:18 AM
Thanks for your reply.
This code seems to be replacing dots in the collection field names. What I meant was the column values - Sorry if this was unclear 🙂
This code seems to be replacing dots in the collection field names. What I meant was the column values - Sorry if this was unclear 🙂
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-02-21 02:01 PM
Hi Karina,
Since you mentioned you want to be able to modify all rows for one specific column, this code should work.
foreach(DataRow row in inputCollection.Rows)
{
row[columnName] = row[columnName].ToString().Replace(".",",");
}
outputCollection = inputCollection;
Since you mentioned you want to be able to modify all rows for one specific column, this code should work.
foreach(DataRow row in inputCollection.Rows)
{
row[columnName] = row[columnName].ToString().Replace(".",",");
}
outputCollection = inputCollection;
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-02-21 02:37 PM
Thanks Nick,
I see that you replied in the other thread as well 😄
I get this error when I try to define columnName as input and run it:
Internal : Could not execute code stage because exception thrown by code stage: Unable to cast object of type 'System.Data.DataColumn' to type 'System.Data.DataRow'.
I see that you replied in the other thread as well 😄
I get this error when I try to define columnName as input and run it:
Internal : Could not execute code stage because exception thrown by code stage: Unable to cast object of type 'System.Data.DataColumn' to type 'System.Data.DataRow'.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-02-21 02:48 PM
It works now - There was a mistake in line 1.
Had it saying:
Had it saying:
foreach(DataRow row in inputCollection.Columns)
instead of:
foreach(DataRow row in inputCollection.Rows)
Thank you very much 🙂 🙂
