Actual need "Subash Dash"
How to remove "DESKTOP-OK4L9CB\" from DESKTOP-CK9M9CB\Subash Dash
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Actual need "Subash Dash"
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Amit MohantyRank #112 · 20K reputationPosted May 31, 2023, 9:10 AM EDT
Check this:
string input = "DESKTOP-CK9M9CB\\Subash Dash"; string output = input.Substring(input.IndexOf('\\') + 1); Console.WriteLine(output);Tuhin PaulRank #7 · 71.9K reputationPosted Jun 8, 2023, 4:44 AM EDT
Supporting to @Amit's code snippet submission:
Input String:
string input = "DESKTOP-CK9M9CB\\Subash Dash";
A string variable named `input` is declared and assigned the value `"DESKTOP-CK9M9CB\\Subash Dash"`. It represents a computer name followed by a backslash (`\`) and a user name.
Output String:
string output = input.Substring(input.IndexOf('\\') + 1);
A new string variable named `output` is declared. The `Substring` method is used to extract a portion of the `input` string starting from the character after the backslash (`\`).
The `IndexOf` method is used to find the position of the first occurrence of the backslash (`\`) within the `input` string. The `+ 1` is added to start the substring from the next character after the backslash. This is because `IndexOf` returns the zero-based index, and adding 1 moves the starting point of the substring to the character after the backslash.