Skip to content

LocalStorage.GetString

method · LocalStorage · cAlgo.API

DesktopCLICloud

Gets a string value from local storage. This method will search all available scopes (Instance -> Type -> Device) and stops on first found value.

Environment behaviour

Cloud — works differently. Key not set in this run returns null and sends LocalStorageException 'Getting local storage data from file is not supported in cloud environment.' to OnException.

Overloads

Signature Description
GetString(string key) Gets a string value from local storage. This method will search all available scopes (Instance -> Type -> Device) and stops on first found value.
GetString(string key, LocalStorageScope localStorageScope) Gets a string value from local storage.

GetString(string key)

Gets a string value from local storage. This method will search all available scopes (Instance -> Type -> Device) and stops on first found value.

string GetString(string key)
api.LocalStorage.GetString(key: str) -> str

Parameters

Name C# type Python type Description
key string str The key of the element to get, max length for keys is 50 characters, and only alphanumeric and space characters are allowed, you can only use space in the middle of key not at the start or end

Returns string — The requested value or an empty string if the provided key is not found

Examples

var lastSignal = LocalStorage.GetString("Last Signal");
if (string.IsNullOrEmpty(lastSignal))
    Print("No signal stored yet");
else
    Print("Last signal: {0}", lastSignal);
lastSignal = api.LocalStorage.GetString("Last Signal")
if not lastSignal:
    api.Print("No signal stored yet")
else:
    api.Print(f"Last signal: {lastSignal}")

GetString(string key, LocalStorageScope localStorageScope)

Gets a string value from local storage.

string GetString(string key, LocalStorageScope localStorageScope)
api.LocalStorage.GetString(key: str, localStorageScope: LocalStorageScope) -> str

Parameters

Name C# type Python type Description
key string str The key of the element to get, max length for keys is 50 characters, and only alphanumeric and space characters are allowed, you can only use space in the middle of key not at the start or end
localStorageScope LocalStorageScope LocalStorageScope The storage scope of the element

Returns string — The requested value or an empty string if the provided key is not found

Examples

var lastSignal = LocalStorage.GetString("Last Signal", LocalStorageScope.Device);
Print("Last signal on this device: {0}", lastSignal);
lastSignal = api.LocalStorage.GetString("Last Signal", LocalStorageScope.Device)
api.Print(f"Last signal on this device: {lastSignal}")