2025-07-03 08:34:35 +00:00
|
|
|
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2025-07-11 08:16:45 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2025-07-03 08:34:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace Rokojori
|
|
|
|
{
|
|
|
|
public static class Text
|
|
|
|
{
|
|
|
|
public static string EscapeAsPathForCommandLine( this string path )
|
|
|
|
{
|
|
|
|
var escaped = path.Replace( "\"", "\\\"" );
|
|
|
|
|
|
|
|
return $"\"{escaped}\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string EnsureEndsWith( this string path, string ending )
|
|
|
|
{
|
|
|
|
if ( ! path.EndsWith( ending ) )
|
|
|
|
{
|
|
|
|
path += ending;
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
2025-07-11 08:16:45 +00:00
|
|
|
|
|
|
|
public static string Replace( this string source, Regex regex, string replacement )
|
|
|
|
{
|
|
|
|
return regex.Replace( source, replacement );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string SubstringAfterMatching( this string source, string match )
|
|
|
|
{
|
|
|
|
var index = source.IndexOf( match );
|
|
|
|
|
|
|
|
return index == -1 ? source : source.Substring( index + match.Length );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static long ToLong( this string source )
|
|
|
|
{
|
|
|
|
return long.Parse( source );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string ReplaceStart( this string source, string start, string replacement = "" )
|
|
|
|
{
|
|
|
|
if ( source.StartsWith( start ) )
|
|
|
|
{
|
|
|
|
return replacement + source.Substring( start.Length );
|
|
|
|
}
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string ReplaceEnd( this string source, string ending, string replacement = "" )
|
|
|
|
{
|
|
|
|
if ( source.EndsWith( ending ) )
|
|
|
|
{
|
|
|
|
return source.Substring( 0, source.Length - ending.Length ) + replacement;
|
|
|
|
}
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
2025-07-03 08:34:35 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|