tryParse

fun tryParse(str: String, forceBinarySize: Boolean = false): DataSize?(source)

Parse a string into a DataSize object.

The string must be in the format of <number><unit> where the unit is one of ["B", "K", "M", "G", "KB", "MB", "GB", "KiB", "MiB", "GiB"] (not case-sensitive).

Parameters

forceBinarySize

If true, always return the data size that's a power of 2. For example, parse("1KB", forceBinarySize = true) will return 1024B, not 1000B as it otherwise would. This is because users commonly think of "GB" as 1024³, not 1000³. Note that this property has no effect if the unit is already a binary unit type (e.g. "1KiB").