I have a file, that contains JSON string. Long string. Approx 700k symbols.
I'm trying to deserialize it.
But it contains symbols like \r
and \n
that should be replaces with comma ,
.
I've tried to do it with Regex
, but it stuck on it without error.
private static readonly Regex Pattern = new Regex("(\r\n|\r|\n)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
Pattern.Replace(dataString, ",");
Also tried to convert string
into StringBuilder
and use simple .Replace
private readonly IDictionary<string, string> replacements = new Dictionary<string, string> { { "\r\n", "," }, { "\r", "," }, { "\n", "," } };
foreach (var replacement in this.replacements)
{
dataStringBuilder.Replace(replacement.Key, replacement.Value);
}
The second case was better but till the time when the file becomes larger. So now I receive stuck for both cases.
Are there any other recommended faster solutions?