Here is how I would write a function to make an acronym in Java style:
string makeAcronym(string str)
{
string result = \"\";
for (in
LINQ can work for this but generally I find it's better to build up string
values using StringBuilder
instance. This allows you to avoid unnecessary string
allocations.
string makeAcronym(string str) {
var builder = new StringBuilder();
for ( var i = 0; i < str.Length; i++ ) {
var c = str[i];
if ( c == ' ' ) {
continue;
}
if ( i == 0 || str[i-1] == ' ' ) {
builder.Append(c);
}
}
return builder.ToString();
}