I have a string
"This is a test string for testing in dotnet4.8 (.net)" 53 chars
The requirement is that if the length of the string is greater than 40 characters
then to replace characters with "" starting from the (.net) moving to the left until the total chars is 40 , so i will end up with
"This is a test string for testing (.net)"
and it doesnt matter if the word is cut off , cause there could be scneario where the string is different but they will always end in (.net)
>Solution :
If I understood you right, you want the actual text to be 34 letters long, so when adding your "(.net)" ends up being 40.
so I guess something in the realms of:
public string Shorten(string s)
{
if(s.Length > 40)
return s.Substring(0,34) + "(.net)";
else
return s;
}