diff --git a/utilcode/src/main/java/com/blankj/utilcode/util/StringUtils.java b/utilcode/src/main/java/com/blankj/utilcode/util/StringUtils.java index 6264f90e55..daef912976 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/util/StringUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/util/StringUtils.java @@ -1,5 +1,7 @@ package com.blankj.utilcode.util; +import android.content.res.Resources; + /** *
  *     author: Blankj
@@ -190,4 +192,59 @@ public static String toSBC(final String s) {
         }
         return new String(chars);
     }
+
+    /**
+     * Return the string value associated with a particular resource ID.  It
+     * will be stripped of any styled text information.
+     * {@more}
+     *
+     * @param id The desired resource identifier, as generated by the aapt
+     *           tool. This integer encodes the package, type, and resource
+     *           entry. The value 0 is an invalid identifier.
+     *
+     * @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist.
+     *
+     * @return String The string data associated with the resource,
+     *         stripped of styled text information.
+     */
+    public static String getString(int id) {
+        return Utils.getApp().getResources().getString(id);
+    }
+
+    /**
+     * Return the string value associated with a particular resource ID,
+     * substituting the format arguments as defined in {@link java.util.Formatter}
+     * and {@link java.lang.String#format}. It will be stripped of any styled text
+     * information.
+     * {@more}
+     *
+     * @param id The desired resource identifier, as generated by the aapt
+     *           tool. This integer encodes the package, type, and resource
+     *           entry. The value 0 is an invalid identifier.
+     *
+     * @param formatArgs The format arguments that will be used for substitution.
+     *
+     * @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist.
+     *
+     * @return String The string data associated with the resource,
+     *         stripped of styled text information.
+     */
+    public static String getString(int id, Object... formatArgs) {
+        return Utils.getApp().getString(id, formatArgs);
+    }
+
+    /**
+     * Return the string array associated with a particular resource ID.
+     *
+     * @param id The desired resource identifier, as generated by the aapt
+     *           tool. This integer encodes the package, type, and resource
+     *           entry. The value 0 is an invalid identifier.
+     *
+     * @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist.
+     *
+     * @return The string array associated with the resource.
+     */
+    public static String[] getStringArray(int id){
+        return Utils.getApp().getResources().getStringArray(id);
+    }
 }