Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class JsonProcessStringHelper
- {
- public static void ProcessStrings(this JObject jObject, Func<string, string> processFunc)
- {
- foreach (var property in jObject.Properties())
- {
- var token = property.Value;
- token.ProcessStrings(processFunc);
- }
- }
- public static void ProcessStrings(this JToken token, Func<string, string> processFunc)
- {
- if (token.Type == JTokenType.Array)
- {
- var arrayToken = (JArray)token;
- foreach (var item in arrayToken)
- {
- item.ProcessStrings(processFunc);
- }
- }
- if (token.Type == JTokenType.Object)
- {
- var tokenObject = token as JObject;
- tokenObject.ProcessStrings(processFunc);
- }
- if (token.Type == JTokenType.String)
- {
- var jValue = token as JValue;
- if (jValue != null)
- {
- var value = jValue;
- value.Value = processFunc(value.Value.ToString());
- }
- }
- }
- public static string SubstringChecked(this string value, int startIndex, int length)
- {
- if ((length - startIndex) >=value.Length)
- return value;
- return value.Substring(startIndex, length);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement