Skip to content

Commit

Permalink
add lastIndexOf with return of Int to String
Browse files Browse the repository at this point in the history
  • Loading branch information
bastie committed Sep 13, 2024
1 parent 9056d06 commit a1bb277
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Sources/JavApi/lang/String+Java.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ extension String {
return toCharArray()[index]
}

public func lastIndexOf (_ char : Character) -> Int {
guard self.contains(char) else {
return -1
}
return distance(from: startIndex, to: self.lastIndex(of: char)!)
}

func lastIndexOf(_ substring: String) -> Int {
guard let range = range(of: substring, options: .backwards) else {
return -1
}
return distance(from: startIndex, to: range.lowerBound)
}

/// The count of String elements
@inlinable
public func lenght () -> Int {
Expand Down

0 comments on commit a1bb277

Please sign in to comment.