Skip to content

'substring(from:)' is deprecated #2

@GaruSivhuy

Description

@GaruSivhuy

extension String {
func indexer(from: Int) -> Index {
return self.index(startIndex, offsetBy: from)
}

func substr(from: Int) -> String {
    let fromIndex = indexer(from: from)
    return substring(from: fromIndex)
}

func substr(to: Int) -> String {
    let toIndex = indexer(from: to)
    return substring(to: toIndex)
}

func substr(with r: Range<Int>) -> String {
    let startIndex = indexer(from: r.lowerBound)
    let endIndex = indexer(from: r.upperBound)
    return substring(with: startIndex..<endIndex)
}

}

Warning with : 'substring(from:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions