The objective is to remove a specified number of spaces from the beginning of a string, where the number of spaces at the start always exceed the required amount. The desired outcome is to obtain modified strings with only the specified number of spaces removed.
Here's an example to illustrate the problem:
text1 = " Hello, world!"
text2 = " Hello, world2!"
num_spaces_to_remove = 5
result1 = " Hello, world!"
result2 = " Hello, world2!"
In this scenario, text1 and text2 represent the original strings with varying numbers of spaces at the beginning. The goal is to remove exactly 5 spaces from each string, resulting in the modified strings result1 and result2, respectively.
My Current solution is something like this -
for c_line in commits_diffs_backport_context:
if c_line.startswith(("+")):
c_line = c_line.replace("+", "")
commits_diffs_backportLines = commits_diffs_backportLines + c_line.replace(c_line[:leadingSpacesBac], "") + "\n"
Looking for a fastest solution. Thanks in advance.