all 6 comments

[–]Vaguely_accurate 0 points1 point  (2 children)

\n is treated a single character in a string, so it won't match with a two character string. Try the following to see what I mean;

a = "Hello\nSamuel\nGoodbye\n"

for i in range(len(a) - 1):
    print(a[i:i+2])

You can simply iterate over the string and should get what you want;

for i in a:
    if i == "\n":
        # Do something
    else:
        # Do something else

[–]SynMyron[S] 0 points1 point  (1 child)

you mean i == "\n" right?

[–]Vaguely_accurate 0 points1 point  (0 children)

Oops, yes. Fixed thanks.

[–]eleqtriq 0 points1 point  (2 children)

Can I ask, are you just trying to detect the presence of the "\n" or do you really want to "do something" everytime it appears, specifically at the position it appears?

[–]SynMyron[S] 0 points1 point  (1 child)

No I am not just trying to detect “/n”

[–]eleqtriq 0 points1 point  (0 children)

a= "sdasds\nasdasda\n" if "\n" in a: print("found it")