EasyLogger.Info("Arguments: " + args[0].NullIfEmpty() ?? string.Empty + args[2].NullIfEmpty() ?? string.Empty + args[3].NullIfEmpty() ?? string.Empty + args[4].NullIfEmpty() ?? string.Empty); public static class StringExtensions { public static string NullIfEmpty(this string s) { return string.IsNullOrEmpty(s) ? null : s; } public static string NullIfWhiteSpace(this string s) { return string.IsNullOrEmpty(s) ? null : s; } } // Get first 3 letter from string char[] array = BarcodeDataTemp.Take(3).ToArray(); // or string str = BarcodeDataTemp.Substring(0, 5); // or with error checking string UIDTemp = null; if(!string.IsNullOrEmpty(BarcodeDataTemp) && BarcodeDataTemp.Length >= 3) UIDTemp = BarcodeDataTemp.Substring(0, 3); // Split char[] delimiterChars = { ' ', ',', '.', ':', '\t' }; string text = "one\ttwo three:four,five six seven"; System.Console.WriteLine($"Original text: '{text}'"); string[] words = text.Split(delimiterChars); System.Console.WriteLine($"{words.Length} words in text:"); foreach (var word in words) { System.Console.WriteLine($"<{word}>"); } // Split string somestring = "this is some text that is here!"; somestring.Split(new[] { "some text" }, StringSplitOptions.None)[0] somestring.Split(new[] { "some text" }, StringSplitOptions.None)[1] // or string[] args = arg.Split(','); substring = str.Split(',')[0];