Skip to content

Commit bd942f3

Browse files
authored
Merge pull request Blankj#687 from shellhub/master
add get string method support
2 parents fdf8b3a + ae1be89 commit bd942f3

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

utilcode/src/main/java/com/blankj/utilcode/util/StringUtils.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.blankj.utilcode.util;
22

3+
import android.content.res.Resources;
4+
35
/**
46
* <pre>
57
* author: Blankj
@@ -190,4 +192,59 @@ public static String toSBC(final String s) {
190192
}
191193
return new String(chars);
192194
}
195+
196+
/**
197+
* Return the string value associated with a particular resource ID. It
198+
* will be stripped of any styled text information.
199+
* {@more}
200+
*
201+
* @param id The desired resource identifier, as generated by the aapt
202+
* tool. This integer encodes the package, type, and resource
203+
* entry. The value 0 is an invalid identifier.
204+
*
205+
* @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist.
206+
*
207+
* @return String The string data associated with the resource,
208+
* stripped of styled text information.
209+
*/
210+
public static String getString(int id) {
211+
return Utils.getApp().getResources().getString(id);
212+
}
213+
214+
/**
215+
* Return the string value associated with a particular resource ID,
216+
* substituting the format arguments as defined in {@link java.util.Formatter}
217+
* and {@link java.lang.String#format}. It will be stripped of any styled text
218+
* information.
219+
* {@more}
220+
*
221+
* @param id The desired resource identifier, as generated by the aapt
222+
* tool. This integer encodes the package, type, and resource
223+
* entry. The value 0 is an invalid identifier.
224+
*
225+
* @param formatArgs The format arguments that will be used for substitution.
226+
*
227+
* @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist.
228+
*
229+
* @return String The string data associated with the resource,
230+
* stripped of styled text information.
231+
*/
232+
public static String getString(int id, Object... formatArgs) {
233+
return Utils.getApp().getString(id, formatArgs);
234+
}
235+
236+
/**
237+
* Return the string array associated with a particular resource ID.
238+
*
239+
* @param id The desired resource identifier, as generated by the aapt
240+
* tool. This integer encodes the package, type, and resource
241+
* entry. The value 0 is an invalid identifier.
242+
*
243+
* @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist.
244+
*
245+
* @return The string array associated with the resource.
246+
*/
247+
public static String[] getStringArray(int id){
248+
return Utils.getApp().getResources().getStringArray(id);
249+
}
193250
}

0 commit comments

Comments
 (0)