Skip to content

Commit

Permalink
add get string method support
Browse files Browse the repository at this point in the history
  • Loading branch information
realDuYuanChao committed Oct 30, 2018
1 parent 3155dcd commit ae1be89
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions utilcode/src/main/java/com/blankj/utilcode/util/StringUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.blankj.utilcode.util;

import android.content.res.Resources;

/**
* <pre>
* author: Blankj
Expand Down Expand Up @@ -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);
}
}

0 comments on commit ae1be89

Please sign in to comment.