# TextUtilsCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/text/TextUtilsCompat.java+class:androidx.core.text.TextUtilsCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***


```
public final class TextUtilsCompat
```

<br />

*** ** * ** ***

Backwards compatible version of `https://developer.android.com/reference/android/text/TextUtils.html`.

## Summary

| ### Public methods |
|---|---|
| `static int` | `https://developer.android.com/reference/androidx/core/text/TextUtilsCompat#getLayoutDirectionFromLocale(java.util.Locale)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/Locale.html locale)` Returns the layout direction for a given Locale |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/TextUtilsCompat#htmlEncode(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html s)` Html-encode the string. |

## Public methods

### getLayoutDirectionFromLocale

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static int getLayoutDirectionFromLocale(@Nullable Locale locale)
```

Returns the layout direction for a given Locale

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/Locale.html locale` | the `https://developer.android.com/reference/java/util/Locale.html` for which we want the layout direction, maybe be `null`. |

| Returns |
|---|---|
| `int` | the layout direction, either `https://developer.android.com/reference/androidx/core/view/ViewCompat#LAYOUT_DIRECTION_LTR()` or `https://developer.android.com/reference/androidx/core/view/ViewCompat#LAYOUT_DIRECTION_RTL()`. |

### htmlEncode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static @NonNull String htmlEncode(@NonNull String s)
```

Html-encode the string.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html s` | the string to be encoded |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | the encoded string |