# react-native: decodeVars URL: https://generaltranslation.com/en-US/docs/react-native/api/strings/decode-vars.mdx --- title: decodeVars description: API reference for the decodeVars() string function --- {/* AUTO-GENERATED: Do not edit directly. Edit the template in content/docs-templates/ instead. */} ## Overview Since `declareVar` adds ICU-compatible markers to source text, it can create issues for any existing string-processing logic. The `decodeVars` function extracts original values from strings that contain `declareVar` markers. ```jsx function getGreeting({ name }) { const greeting = "Hello, " + declareVar(name); // "Hello, {_gt_, select, other {Brian}}" const decodedGreeting = decodeVars(greeting); // "Hello, Brian" <- the string as if `declareVar` was never used return decodedGreeting; } ``` Because `declareVar` only affects encoded strings, it is only meant for use with source strings and has no effects on translated strings. **String Processing:** Use `decodeVars` when you need to process strings that contain `declareVar` markers with existing string manipulation logic. ## Reference ### Parameters | Name | Type | Description | |-----------------------|--|-----------------------------------------------------------------------------| | `icuString` | `string` | A string containing ICU markers from `declareVar` calls. | ### Returns A string with ICU markers removed, containing the original variable values. --- ## Example ### Basic usage Extract original values from strings with variable markers. ```jsx copy import { declareVar, decodeVars } from 'gt-react-native'; const encodedVar = declareVar(name); // "{_gt_, select, other {Alice}}" const decodedVar = decodeVars(encodedVar); // "Alice" ``` ### Multiple variables `decodeVars` can be used with multiple variables. ```jsx copy import { declareVar, decodeVars } from 'gt-react-native'; const name1 = "Alice"; const name2 = "Bob"; const encodedVar = "Hello, " + declareVar(name1) + "! My name is " + declareVar(name2); // "Hello, {_gt_, select, other {Alice}}! My name is {_gt_, select, other {Bob}}" const decodedVar = decodeVars(encodedVar); // "Hello, Alice! My name is Bob" ``` --- ## Notes * Only use `decodeVars` when you need to process strings containing `declareVar` markers * The function specifically targets ICU MessageFormat patterns created by `declareVar` * Original variable values are preserved exactly as they were before encoding * Does not affect translation processing - only removes markers for string manipulation * decodeVars is not a general ICU MessageFormat parser and should not be used on arbitrary ICU strings ## Next steps * See [`declareVar`](/docs/react-native/api/strings/declare-var) for marking dynamic content * See [`declareStatic`](/docs/react-native/api/strings/declare-static) for creating static function calls * See [`msg`](/docs/react-native/api/strings/msg) for string encoding and decoding patterns