Extensions on
String
Properties
Methods
withPrefixIdentation(count:)
public func withPrefixIdentation(count: Int = 1) -> String
Add identation in front of string
Example
let name = "Wendy Liga"
let nameWithIdentation = "Wendy Liga".withPrefixIdentation()
print(nameWithIdentation) -> " Wendy Liga"
Parameters
Name | Type | Description |
---|---|---|
count | Int |
number of identation |
Returns | String with prefix Identation |
separate(with:offset:)
public func separate(with rightSide: String, offset: Int) -> String
Separate two text with spesific offset
This function will create table like string
Example:
String an collection of characters
Int containing number
Double bigger than Int
Parameters
Name | Type | Description |
---|---|---|
with | String |
right side text |
offset | Int |
how many offset from left side |
Returns | String with separation, look Example for mode detail |
withoutPrefix(_:replaceWith:)
public func withoutPrefix(_ prefix: String, replaceWith newString: String = "") -> String
remove prefix on string
Example:
let string = "$10.000"
let stringWithoutPrefix = string.withoutPrefix("$") -> "10.000"
or
let string = "~/document"
let stringWithoutPrefix = string.withoutPrefix(".") -> "~/document"
Parameters
Name | Type | Description |
---|---|---|
prefix | String |
text you want to remove |
replaceWith | String |
if you want to replace with spesific string |
Returns | String with remove prefix |
withoutSuffix(_:replaceWith:)
public func withoutSuffix(_ suffix: String, replaceWith newString: String = "") -> String
remove suffix on string
Example:
let string = "10.000."
let stringWithoutPrefix = string.withoutPrefix(".") -> "10.000"
or
let string = "~/document"
let stringWithoutPrefix = string.withoutPrefix(".") -> "~/document"
Parameters
Name | Type | Description |
---|---|---|
suffix | String |
text you want to remove |
replaceWith | String |
if you want to replace with spesific string |
Returns | String with remove suffix |
noWhiteSpace(replace:)
public func noWhiteSpace(replace with: NoWhiteSpaceReplacer) -> String
remote white space inside String
with several mode
-
none : will vanish all white space like "This is Amazing" into "ThisIsAmazing"
-
camelCase: remove whitespace and make sure every first character of words seperated with white space will be capitalized like "my name is wendy" into "MyNameIsWendy"
-
snakeCase: replace whitespace with _ like "hello world" into "hello_world"
capitalizeFirstLetter()
public func capitalizeFirstLetter() -> String
Capitalize first letter
Example: string -> String wendy -> Wendy