#c# exercise extension methods

12 messages · Page 1 of 1 (latest)

still glade
#

c# exercise extension methods

opal dust
#

return str.Substring(index + delimiter.Length);
assuming index is say 10 and delimiter is just a ; or whatever - just a character of length 1 - the result of index + delimiter.Length will be what? and thefore how long (.Length) will the result of that substring be?

#

can you show the testing results for your solution?

still glade
#

yes i can

#

wait a sec

#

im trying to do all tasks right now

#
public static class LogAnalysis 
{
    // TODO: define the 'SubstringAfter()' extension method on the `string` type            
    public static string SubstringAfter(this string str, string delimiter)
    {
        int index = str.IndexOf(delimiter);
        if(index == -1){
            return str;
        }
        return str.Substring(index + delimiter.Length);
    }
    // TODO: define the 'SubstringBetween()' extension method on the `string` type
    public static string SubstringBetween(this string str, string start, string end)
    {
        int startIndex = str.IndexOf(start);
        startIndex += start.Length;
        int endIndex = str.IndexOf(end, startIndex);
        return str.Substring(startIndex, endIndex - startIndex);
    }
    // TODO: define the 'Message()' extension method on the `string` type
    public static string Message(this string str)
    {
        return str.SubstringAfter(": ");
    }
    // TODO: define the 'LogLevel()' extension method on the `string` type
    public static string LogLevel(this string str)
    {
        return str.SubstringBetween("[", "]");
    }
}
#

error is wait..

#

nevermind i got it

#

there was a stupid misstake by writing