mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-13 03:35:04 +00:00
feat: Adding UnEnquote string util method
This commit is contained in:
@@ -178,5 +178,12 @@ namespace ICD.Common.Utils.Tests
|
||||
{
|
||||
Assert.AreEqual(expected, StringUtils.Enquote(input));
|
||||
}
|
||||
|
||||
[TestCase("\"test\"", "test")]
|
||||
[TestCase("\"test test\"", "test test")]
|
||||
public void UnEnquoteTest(string input, string expected)
|
||||
{
|
||||
Assert.AreEqual(expected, StringUtils.UnEnquote(input));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,5 +707,21 @@ namespace ICD.Common.Utils
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the start and trailing double quote from the string if BOTH are present.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static string UnEnquote(string value)
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException("value");
|
||||
|
||||
if (value.StartsWith('"') && value.EndsWith('"'))
|
||||
return value.Substring(1, value.Length - 2);
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user