question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IndexOutOfRange exception in StringExtensions.TrimFirstLine

See original GitHub issue
System.IndexOutOfRangeException occurred
  StackTrace:
       at System.Text.StringBuilder.get_Chars(Int32 index)
       at ExCSS.Model.Extensions.StringExtensions.TrimFirstLine(StringBuilder builder)
       at ExCSS.StyleSheet.ToString(Boolean friendlyFormat, Int32 indentation)
       at ExCSS.StyleSheet.ToString()

public static StringBuilder TrimFirstLine(this StringBuilder builder)
        {
            if (builder.Length > 0) // this check must be moved to "while"
            {
                while (builder[0] == '\r' || builder[0] == '\n' || builder[0] == '\t')
                {
                    builder.Remove(0, 1);
                }
            }

            return builder;
        }

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
MaceWinducommented, Oct 24, 2015

Well, I was testing different inputs and it was failing like that on latest released version on empty string (string.Empty). On current code base it doesn’t fail due to some other changes since last release, so I have no inputs to reproduce it now using parser. But you still can reproduce it using isolated test for this extension method (and TrimLastLine):

new StringBuilder("\r\n").TrimLastLine();
new StringBuilder("\r\n").TrimFirstLine();
0reactions
TylerBrinkscommented, May 21, 2016

Looking into it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - What is an IndexOutOfRangeException ...
This exception means that you're trying to access a collection item by index, using an invalid index. An index is invalid when it's...
Read more >
IndexOutOfRangeException Class (System)
The exception that is thrown when an attempt is made to access an element of an array or collection with an index that...
Read more >
IndexOutOfRangeException in C#
It occurs when an invalid index is used to access a member of a collection. The following example throws the IndexOutOfRange exception: Example:....
Read more >
IndexOutOfRangeException - ERP 10
Hi all, I'm new to Epicor, and we've recently been having a few issues. Lately, a service that we wrote that retrieves and...
Read more >
C# IndexOutOfRangeException
This C# exception will typically occur when a statement tries to access an element at an index greater than the maximum allowable index....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found