📉Text - NKS0048

Use TextTools.SplitNewLines()

This analyzer provides the following strings:

Context
String

Error List

Caller uses .Split("\r\n") instead of TextTools.SplitNewLines()

Suggestion Box

Use TextTools.SplitNewLines() instead of .Split("\r\n")

Description

TextTools.SplitNewLines() simplifies the readability of the split by new lines function.

Extended Description

This code analyzer detects the usage of Split("\r\n") from the String class found in the System namespace.

Splitting by new lines is a good way to get the lines from your string. However, the complexity needs to be reduced so that more readability is achieved. As a result, SplitNewLines() is here to do it in the simplest way possible.

Analysis Comparison

To get a brief insight about how this analyzer works, compare the two code blocks shown to you below:

Before the fix

Somewhere in your mod code...
public static void MyFunction()
{
    string var = "Hello\r\nWorld!";
    var split = var.Split("\r\n");
}

After the fix

Somewhere in your mod code...
public static void MyFunction()
{
    string var = "Hello\r\nWorld!";
    var split = var.SplitNewLines();
}

After the fix (alternate)

Somewhere in your mod code
public static void MyFunction()
{
    string var = "Hello\r\nWorld!";
    var split = var.SplitNewLinesOld();
}

Suppression

You can suppress this suggestion by including it in the appropriate place, whichever is convenient.

For more information about how to suppress any warning issued by the Nitrocid analyzer, visit the below page:

Recommendation

We recommend that every caller which use this function use the recommended abovementioned method.

Last updated