<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/readLine(strippingNewline:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s8readLine16strippingNewlineSSSgSb_tF"
  },
  "title" : "readLine(strippingNewline:)"
}
-->

# readLine(strippingNewline:)

Returns a string read from standard input through the end of the current
line or until EOF is reached.

```
func readLine(strippingNewline: Bool = true) -> String?
```

## Parameters

`strippingNewline`

If `true`, newline characters and character
combinations are stripped from the result; otherwise, newline characters
or character combinations are preserved. The default is `true`.

## Return Value

The string of characters read from standard input. If EOF has
already been reached when `readLine()` is called, the result is `nil`.

## Discussion

Standard input is interpreted as `UTF-8`. Invalid bytes are replaced by
Unicode [replacement characters](https://unicode.org/glossary/#replacement_character).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)