<p>I have a string that is like below.</p>

<pre><code>,liger, unicorn, snipe
</code></pre>

<p>in other languages I'm familiar with I can just do a string.trim(",") but how can I do that in c#?</p>

<p>Thanks.</p>

<hr>

<p><em>There's been a lot of back and forth about the StartTrim function.  As several have pointed out, the StartTrim doesn't affect the primary variable.  However, given the construction of the data vs the question, I'm torn as to which answer to accept.  True the question only wants the first character trimmed off not the last (if anny), however, there would never be a "," at the end of the data.  So, with that said, I'm going to accept the first answer that that said to use StartTrim assigned to a new variable.</em></p>

[{'answer_id': 73650, 'author': 'Bob King', 'author_id': 6897, 'author_profile': 'https://Stackoverflow.com/users/6897', 'pm_score': 0, 'selected': False, 'text': '<pre><code>if (s.StartsWith(",")) {\n    s = s.Substring(1, s.Length - 1);\n}\n</code></pre>\n'}, {'answer_id': 73652, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 4, 'selected': False, 'text': '<pre><code>string s = ",liger, unicorn, snipe";\ns.TrimStart(\',\');\n</code></pre>\n'}, {'answer_id': 73656, 'author': 'Kieran Benton', 'author_id': 5777, 'author_profile': 'https://Stackoverflow.com/users/5777', 'pm_score': 0, 'selected': False, 'text': '<pre><code>string t = ",liger, unicorn, snipe".TrimStart(new char[] {\',\'});\n</code></pre>\n'}, {'answer_id': 73658, 'author': 'pilsetnieks', 'author_id': 6615, 'author_profile': 'https://Stackoverflow.com/users/6615', 'pm_score': 0, 'selected': False, 'text': '<p>The same way as everywhere else: <a href="http://msdn.microsoft.com/en-us/library/d4tt83f9.aspx" rel="nofollow noreferrer">string.trim</a></p>\n'}, {'answer_id': 73660, 'author': 'Matt Dawdy', 'author_id': 232, 'author_profile': 'https://Stackoverflow.com/users/232', 'pm_score': 0, 'selected': False, 'text': '<pre><code>    string s = ",liger, tiger";\n\n    if (s.Substring(0, 1) == ",")\n        s = s.Substring(1);\n</code></pre>\n'}, {'answer_id': 73665, 'author': 'chakrit', 'author_id': 3055, 'author_profile': 'https://Stackoverflow.com/users/3055', 'pm_score': 0, 'selected': False, 'text': '<p>Did you mean trim all instances of "," in that string?</p>\n\n<p>In which case, you can do:</p>\n\n<pre><code>s = s.Replace(",", "");\n</code></pre>\n'}, {'answer_id': 73668, 'author': 'Akselsson', 'author_id': 8862, 'author_profile': 'https://Stackoverflow.com/users/8862', 'pm_score': 1, 'selected': False, 'text': '<p>",liger, unicorn, snipe".Trim(\',\') -> "liger, unicor, snipe"</p>\n'}, {'answer_id': 73671, 'author': 'Magus', 'author_id': 2188, 'author_profile': 'https://Stackoverflow.com/users/2188', 'pm_score': 1, 'selected': False, 'text': "<p>Try string.Trim(',') and see if that does what you want.</p>\n"}, {'answer_id': 73676, 'author': 'Clinton Pierce', 'author_id': 8173, 'author_profile': 'https://Stackoverflow.com/users/8173', 'pm_score': 0, 'selected': False, 'text': '<p>Just use Substring to ignore the first character (or assign it to another string);</p>\n\n<pre><code> string o = ",liger, unicorn, snipe";\n string s = o.Substring(1);\n</code></pre>\n'}, {'answer_id': 73681, 'author': 'Jay Bazuzi', 'author_id': 5314, 'author_profile': 'https://Stackoverflow.com/users/5314', 'pm_score': 2, 'selected': False, 'text': '<p>.net strings can do Trim() and TrimStart().  Because it takes <code>params</code>, you can write:</p>\n\n<pre><code>",liger, unicorn, snipe".TrimStart(\',\')\n</code></pre>\n\n<p>and if you have more than one character to trim, you can write:</p>\n\n<pre><code>",liger, unicorn, snipe".TrimStart(",; ".ToCharArray())\n</code></pre>\n'}, {'answer_id': 73708, 'author': 'bentford', 'author_id': 946, 'author_profile': 'https://Stackoverflow.com/users/946', 'pm_score': 0, 'selected': False, 'text': '<p>See: <a href="http://msdn.microsoft.com/en-us/library/d4tt83f9.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/d4tt83f9.aspx</a></p>\n\n<pre><code>        string animals = ",liger, unicorn, snipe";\n\n        //trimmed will contain "liger, unicorn, snipe"\n        string trimmed = word.Trim(\',\');\n</code></pre>\n'}, {'answer_id': 73734, 'author': 'RickL', 'author_id': 7261, 'author_profile': 'https://Stackoverflow.com/users/7261', 'pm_score': 5, 'selected': True, 'text': '<pre><code>string sample = ",liger, unicorn, snipe";\nsample = sample.TrimStart(\',\'); // to remove just the first comma\n</code></pre>\n\n<p>Or perhaps:</p>\n\n<pre><code>sample = sample.Trim().TrimStart(\',\'); // to remove any whitespace and then the first comma\n</code></pre>\n'}, {'answer_id': 73749, 'author': 'hamishmcn', 'author_id': 3590, 'author_profile': 'https://Stackoverflow.com/users/3590', 'pm_score': 1, 'selected': False, 'text': '<p>Note, the <em>original</em> string is left untouched, Trim will return you a new string:</p>\n\n<pre><code>string s1 = ",abc,d";\nstring s2 = s1.TrimStart(",".ToCharArray());\nConsole.WriteLine("s1 = {0}", s1);\nConsole.WriteLine("s2 = {0}", s2);\n</code></pre>\n\n<p>prints:</p>\n\n<pre><code>s1 = ,abc,d\ns2 = abc,d\n</code></pre>\n'}, {'answer_id': 74536, 'author': 'justin.m.chase', 'author_id': 12958, 'author_profile': 'https://Stackoverflow.com/users/12958', 'pm_score': 2, 'selected': False, 'text': '<p>here is an easy way to not produce the leading comma to begin with:</p>\n\n<pre><code>string[] animals = { "liger", "unicorn", "snipe" };\nstring joined = string.Join(", ", animals);\n</code></pre>\n'}, {'answer_id': 79881, 'author': 'Wonko', 'author_id': 14842, 'author_profile': 'https://Stackoverflow.com/users/14842', 'pm_score': 1, 'selected': False, 'text': '<pre><code>string s = &quot;,liger, unicorn, snipe&quot;;\ns = s.TrimStart(\',\');\n</code></pre>\n<p>It\'s important to assign the result of TrimStart to a variable. As it says on the <a href="http://msdn.microsoft.com/en-us/library/system.string.trimstart.aspx" rel="nofollow noreferrer">TrimStart page</a>, &quot;This method does not modify the value of the current instance. Instead, it returns a new string...&quot;.</p>\n<p>In .NET, strings don\'t change.</p>\n'}, {'answer_id': 80283, 'author': 'abjbhat', 'author_id': 15048, 'author_profile': 'https://Stackoverflow.com/users/15048', 'pm_score': 1, 'selected': False, 'text': '<p>you can use this </p>\n\n<p>,liger, unicorn, snipe".TrimStart(\',\');</p>\n'}, {'answer_id': 80517, 'author': 'benPearce', 'author_id': 4490, 'author_profile': 'https://Stackoverflow.com/users/4490', 'pm_score': 2, 'selected': False, 'text': '<p>string.TrimStart(\',\') will remove the comma, however you will have trouble with a split operation due to the space after the comma. \nBest to join just on the single comma or use </p>\n\n<blockquote>\n  <p>Split(", ".ToCharArray(),StringSplitOptions.RemoveEmptyEntries);</p>\n</blockquote>\n'}]
['https://Stackoverflow.com/questions/73629', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/730/']