fork download
  1. public class Main {
  2. public static void main(String[] args) {
  3. // 原始字符串
  4. String rawString = "'[]'|1007651102246_PC--chefgapparoniTTV|'[]'|1008939370770_PC--N3LAS|'[]'|1009614872477_PC--RalitsTwitch|'[]'|1010071713191_PC--Twitch-Dnnnn|'[]'|1007970864045_PC--DSK_788|'[]'|1008053680955_PC--douyin_小白|'[]'|1008795761561_PC--卡莎|'[]'|1008348758076_PC--RC_SangJoon|'[]'|1007870483256_PC--Vcan_backhorizon|'[]'|1007376998248_PC--Varayn|'[]'|1010617823111_PC--E8_Shooby|";
  5.  
  6. // 拆分字符串以提取每個 UID 和名稱
  7. String[] parts = rawString.split("\\|");
  8.  
  9. // 遍歷提取 UID 和名稱
  10. for (int i = 1; i < parts.length; i += 2) {
  11. // 檢查是否是有效的 UID 部分
  12. if (parts[i].contains("_")) {
  13. String[] uidAndName = parts[i].split("_");
  14. try {
  15. long uid = Long.parseLong(uidAndName[0].trim()); // 提取 UID
  16. String name = uidAndName[1].split("--")[1].trim(); // 提取名稱
  17.  
  18. // 打印結果
  19. System.out.println("{\"uid\":" + uid + ",\"name\":\"" + name + "\"}");
  20. } catch (NumberFormatException e) {
  21. System.out.println("無法解析 UID: " + uidAndName[0]);
  22. }
  23. }
  24. }
  25. }
  26. }
Success #stdin #stdout 0.15s 58044KB
stdin
Standard input is empty
stdout
{"uid":1007651102246,"name":"chefgapparoniTTV"}
{"uid":1008939370770,"name":"N3LAS"}
{"uid":1009614872477,"name":"RalitsTwitch"}
{"uid":1010071713191,"name":"Twitch-Dnnnn"}
{"uid":1007970864045,"name":"DSK"}
{"uid":1008053680955,"name":"douyin"}
{"uid":1008795761561,"name":"卡莎"}
{"uid":1008348758076,"name":"RC"}
{"uid":1007870483256,"name":"Vcan"}
{"uid":1007376998248,"name":"Varayn"}
{"uid":1010617823111,"name":"E8"}