Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}