text processing(COPILOTでの検索結果)

def process_text(text): # Check if the text contains CRLF (Windows line endings) if "\r\n" in text: # Split the text using CRLF lines = text.split("\r\n") else: # Assume UNIX line endings (LF) and split the text using LF lines = text.split("\n")

# Process each line
for line in lines:
    print(line)

例として使用するテキスト

text_with_crlf = "Line 1\r\nLine 2\r\nLine 3" process_text(text_with_crlf)

例として使用するUNIXの改行コードを含むテキスト

text_with_unix_line_endings = "Line 1\nLine 2\nLine 3" process_text(text_with_unix_line_endings)