I have multiple strings in the following format "(space)> sometext > anothertext".
"sometext" and "anothertext" can be anything - they can vary in length and content.
The prefix of each string is always "(space)>", while (space) is any given number of space characters up until a given maximum length.
Examples:
Max prefix length is 10.
1. "> here is same 1 > sample 1"
2. " > here is sample 2 > sample 2 indeed"
3. " > a very long spaced prefix > spaced prefix"
I need to align all the prefixes to the same space length. E.g., aligning all to 10 space characters...
1. " > here is same 1 > sample 1"
2. " > here is sample 2 > sample 2 indeed"
3. " > a very long spaced prefix > spaced prefix"
I am using Regex to achieve this goal with the below code:
int padding = 10;
Regex prefix = new Regex(@"^(\s*)>.*");
Match prefix_match = prefix.Match(line);
if (prefix_match.Success == true)
{
string space_padding = new string(' ', padding - prefix_match.Groups[1].Value.Length);
return prefix.Replace(line, space_padding);
}
return line;
But I always get as a result is a 10 space length string...
string.Trim()and add yours spaces, regex seems to be overly complicating this