In C#, how do I perform a Left( ) and Right( ) string function on a string?
For example:
Right("This is a beautiful day",3)
would equal
"day"
~~~~
Left("This is a beautiful day",3)
would equal
"Thi"
What I want to do is:
1) Assign a value to a string.
2) Determine if the string ends with a particular substring.
3) If so, truncate the string so the string equals the string minus the substring (on the end).
4) Concatenate a new substring on the end of the main string.
Scenario 1
//Main string = "This is a beautiful day,Accounts"
//substring to delete equals ",Accounts"
//replacement substring equals ",12345"
//Truncated string now equals: "This is a beautiful day"
//Append replacement substring
//Main string now equals "This is a beautiful day,12345"
Scenario 2
//Main string = "This is a beautiful day,Buddy"
//substring to delete equals ",Accounts"
//replacement substring equals ",12345"
//substring sought for not found so Main String still now equals: "This is a beautiful day,Buddy"
//Do not Append replacement substring
//Main string still equals "This is a beautiful day,Buddy"
Start Free Trial