StringExtensions
QuantConnect.StringExtensions
Bases: Object
Provides extension methods for properly parsing and serializing values while properly using an IFormatProvider/CultureInfo when applicable
index_of_invariant
index_of_invariant(value: str, character: str) -> int
index_of_invariant(
value: str, substring: str, ignore_case: bool = False
) -> int
Signature descriptions:
-
Gets the index of the specified character using StringComparison
-
Gets the index of the specified substring using StringComparison or System.StringComparison.InvariantCultureIgnoreCase when ignore_case is true
to_string_invariant
to_string_invariant(convertible: IConvertible) -> str
to_string_invariant(
formattable: IFormattable, format: str
) -> str
Signature descriptions:
-
Converts the provided value to a string using CultureInfo
-
Formats the provided value using the specified format and CultureInfo
convert_invariant
convert_invariant(
value: Any, conversion_type: Type
) -> Object
Converts the provided value as conversion_type using CultureInfo
ends_with_invariant
ends_with_invariant(
value: str, ending: str, ignore_case: bool = False
) -> bool
Checks if the string ends with the provided ending using CultureInfo while optionally ignoring case.
invariant
invariant(formattable: FormattableString) -> str
Non-extension method alias for FormattableString.Invariant This supports the using static QuantConnect.StringExtensions syntax and is aimed at ensuring all formatting is piped through this class instead of alternatively piping through directly to FormattableString.Invariant
last_index_of_invariant
last_index_of_invariant(
value: str, substring: str, ignore_case: bool = False
) -> int
Gets the index of the specified substring using StringComparison or System.StringComparison.InvariantCultureIgnoreCase when ignore_case is true
safe_substring
safe_substring(
value: str, start_index: int, length: int
) -> str
Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length.
starts_with_invariant
starts_with_invariant(
value: str, beginning: str, ignore_case: bool = False
) -> bool
Checks if the string starts with the provided beginning using CultureInfo while optionally ignoring case.
to_iso_8601_invariant
to_iso_8601_invariant(
date_time: Union[datetime, date],
) -> str
Provides a convenience methods for converting a DateTime to an invariant ISO-8601 string
truncate
truncate(value: str, max_length: int) -> str
Truncates a string to the specified maximum length
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The string |
required |
max_length
|
int
|
The maximum allowed string |
required |
Returns:
| Type | Description |
|---|---|
str
|
A new string with max_length characters if the original one's length was greater than the maximum allowed length. Otherwise, the original string is returned. |