String字符串使用split()方法按特殊符号进行分隔

本文介绍了如何在Java和Python中使用split()方法按特定特殊字符进行字符串分隔,包括圆括号、符号、斜杆、按位或符号及点号等。针对包含多个分隔符的情况,演示了如何利用正则表达式实现更复杂的分隔,例如在处理'='和'and'分隔键值对的字符串。同时,强调了在处理连续分隔符时,使用正确正则表达式的重要性,如split("[,]")来处理逗号分隔的字符串。" 53509196,5725170,Linux系统下识别USB设备的4种方法,"['Linux系统', '设备管理', '命令行工具', '硬件识别']
摘要由CSDN通过智能技术生成

日常工作中常见的特殊字符,比如:
圆括号( :split("[(]")

符号:split("\")

斜杆():split("\\")

按位或符号(|):split("\|")

.dot:split("\.")

如果在一个字符串中有多个分隔符,可以用“|”作为连字符,比如"name=Bobandage=19andaddress=Beijing",把key和value都分隔出来,可以用split("=|and")

还有的复杂字符串,如果按常规操作,比如按逗号分隔,使用str.split(",")进行分隔,分隔出来的结果不是我们相像的一样,更不是我们想要的结果,比如下面的字符串:

String str = "{"symbol":"KZ","bc2":0,"bc1":0,"bc4":0,"current":null,"bc3":0,"bc5":0,"sc1":0,"bp1":0,"sc3":0,"sc2":0,"bp3":0,"sc5":0,"bp2":0,"sc4":0,"sellpct":0,"bp5":0,"bp4":0,"diff":0,"sp2":0,"sp1":0,"sp4":0,"sp3":0,"sp5":0,"time":1492128000000,"buypct":0,"ratio":0},{"data":{"market":{"status_id":2,"time_zone_desc":null,"region":"US","time_zone":"America/New_York","status":"盘前交易"},"quote":{"current_ext":null,"symbol":"KZ","high52w":null,"percent_ext":null,"delayed":0,"type":0,"tick_size":0.01,"float_shares":null,"high":null,"float_market_capital":null,"timestamp_ext":1611219316579,"lot_size":1,"lock_set":1,"chg":null,"eps":0.8583956470504864,"last_close":7.495,"profit_four":4.043329E7,"volume":null,"volume_ratio":null,"profit_forecast":4.5778666666666664E7,"turnover_rate":null,"low52w":null,"name":"空中网","exchange":"","pe_forecast":null,"total_shares":47103326,"status":0,"code":"KZ","goodwill_in_net_assets":26.62193188386609,"avg_price":null,"percent":null,"psr":null,"amplitude":null,"current":7.4
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值