"["1","2"]"转换为字符串数组
时间: 2023-09-12 21:11:57 浏览: 99
C#字符串数组转换为整形数组的方法
要将字符串"["1","2"]"转换为字符串数组,可以使用split方法来实现。首先,需要去掉字符串中的引号和方括号。然后,使用split方法将字符串按照逗号分割成字符数组。以下是转换的步骤:
1. 去除字符串中的引号和方括号,可以使用replace方法。将字符串中的双引号和方括号替换为空字符串。
2. 使用split方法,将字符串按照逗号分割成字符数组。
以下是示例代码:
```java
String str = "[\"1\",\"2\"]";
str = str.replace("\"", "").replace("[", "").replace("]", "");
String[] arr = str.split(",");
```
这样就可以将字符串"["1","2"]"转换为字符串数组["1", "2"]。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [字符串转换为字符串数组和字节数组,字符串数组转换为字节数组](https://blog.csdn.net/qq_22889875/article/details/78624716)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [cell2char:将字符串元胞数组转换为字符数组的函数。-matlab开发](https://download.csdn.net/download/weixin_38688855/19291586)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [字符串数组转换为字符串。](https://blog.csdn.net/F_x_i_a_o_l_i_n_g_/article/details/105422934)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文