Sdílet prostřednictvím


TextUtils.MakeSafeForPresentation Method

Definition

Remove html, remove bad characters, and truncate string.

public static string MakeSafeForPresentation (string unclean, int maxCharactersToConsider, float ellipsizeDip, Android.Text.SafeStringFlagMode flags);
static member MakeSafeForPresentation : string * int * single * Android.Text.SafeStringFlagMode -> string

Parameters

unclean
String

The input string

maxCharactersToConsider
Int32

The maximum number of characters of unclean to consider from the input string. 0 disables this feature.

ellipsizeDip
Single

Assuming maximum length of the string (in dip), assuming font size 42. This is roughly 50 characters for ellipsizeDip == 1000.<br /> Usually ellipsizing should be left to the view showing the string. If a string is used as an input to another string, it might be useful to control the length of the input string though. 0 disables this feature.

flags
SafeStringFlagMode

Flags controlling cleaning behavior (Can be #SAFE_STRING_FLAG_TRIM, #SAFE_STRING_FLAG_SINGLE_LINE, and #SAFE_STRING_FLAG_FIRST_LINE)

Returns

The cleaned string

Remarks

Remove html, remove bad characters, and truncate string.

This method is meant to remove common mistakes and nefarious formatting from strings that were loaded from untrusted sources (such as other packages).

This method first Html#fromHtml treats the string like HTML and then ... <ul> <li>Removes new lines or truncates at first new line <li>Trims the white-space off the end <li>Truncates the string </ul> ... if specified.

Java documentation for android.text.TextUtils.makeSafeForPresentation(java.lang.String, int, float, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to