used_memory:4429304\r\nused_memory_human:4.22M\r\nused_memory_rss:4327696\r\nused_memory_peak:4429304\r\nused_memory_peak_human:4.22Mused_memory_lua:33792\r\nmem_fragmentation_ratio:0.98\r\nmem_allocator:dlmalloc-2.8\r\n有類似于上面格式的一個字符串,現在我想根據前面的類型(比如used_memory)取后面的值(對應的4429304),在一個函數里面寫,函數傳入的參數為type(type="used_memory"或者type="used_memory_peak"等等),得到對應type相應的取值,怎么寫呢
2 回答

慕森卡
TA貢獻1806條經驗 獲得超8個贊
123456 | public static String getStr(String type){ String str= "used_memory:4429304\r\n" ; str=str.substring(str.indexOf(type)+type.length(),str.length()); System.out.println( "需要的值=" +str); return str; } |
添加回答
舉報
0/150
提交
取消