in reply to difference between two lines

What have you tried and how did your code fail?

Some ideas would be:

You could remove all spaces from both lines. If they are equal, the difference was only the blank space.

If you want to know if two lines only differ by exactly one blank space, check first, if the absolute difference in their lengths is 1. Then do the above check.

Alternatively, split both strings on spaces and check if the resulting lists are the same.

Replies are listed 'Best First'.
Re^2: difference between two lines
by vinoth.ree (Monsignor) on Jul 30, 2018 at 09:13 UTC
    Hi Corion

    I tried the first option(remove all spaces from both lines and compare). I thought there could be best way, that's why posted this question.


    All is well. I learn by answering your questions...

      So the first option worked? If so, there's no need for a "best way". If your code has some issues you'll have to be more specific, rather than hope someone provides a solution actually fits your needs without knowing them. Or if you want advice about your code, you'll have to post it.

      Edited: in hindsight my previous formulation sounded harsher than intended.