-4

I want to change string to comma in Eval function inside Repeater -> item templete When i use it

Eval("RoleName").ToString().Replace(" ", ", ")

it only shows comma on first string word not all of them

Memeber, Admin SupuerAdmin User

But i want

Member, Admin, SuperAdmin, User

2 Answers2

2

use aggregate

var a = "Memeber Admin SupuerAdmin User";
var z = a.Split(' ').Aggregate((x, y) => x + ", " + y);
System.Console.WriteLine(z);
dariogriffo
  • 4,148
  • 3
  • 17
  • 34
0

Use String.Join to transform an array of strings into a single delimited string.

String.Join(", ", Eval("RoleName"));

I'm not sure on the result type of Eval("RoleName"), but if it is a string[], it will work.

Josh
  • 16,286
  • 25
  • 113
  • 158