Label: 1, Position: (0, 0), Size: 2212 x 1578 Label: 2, Position: (1596, 1281), Size: 28 x 17 Label: 3, Position: (1578, 1286), Size: 25 x 18 Label: 4, Position: (1619, 1288), Size: 42 x 43 Label: 5, Position: (1534, 1289), Size: 44 x 11给每一行两边加上分号
时间: 2024-03-22 20:38:30 浏览: 53
switchable:用漂亮的iPhone风格的开关按钮代替复选框
你可以使用字符串操作和循环来实现这个转换。下面是一个示例代码:
```python
string = "Label: 1, Position: (0, 0), Size: 2212 x 1578\nLabel: 2, Position: (1596, 1281), Size: 28 x 17\nLabel: 3, Position: (1578, 1286), Size: 25 x 18\nLabel: 4, Position: (1619, 1288), Size: 42 x 43\nLabel: 5, Position: (1534, 1289), Size: 44 x 11"
lines = string.split("\n")
new_lines = []
for line in lines:
new_line = f"; {line} ;"
new_lines.append(new_line)
result = "\n".join(new_lines)
print(result)
```
这个代码会输出以下结果:
```
; Label: 1, Position: (0, 0), Size: 2212 x 1578 ;
; Label: 2, Position: (1596, 1281), Size: 28 x 17 ;
; Label: 3, Position: (1578, 1286), Size: 25 x 18 ;
; Label: 4, Position: (1619, 1288), Size: 42 x 43 ;
; Label: 5, Position: (1534, 1289), Size: 44 x 11 ;
```
注意,这个代码假设输入的字符串格式都相同。如果输入的字符串格式不同,可能需要对代码进行相应的修改。
阅读全文