txt文件中Label: 2, Position: (1596, 1281), Size: 28 x 17怎么改为(1596,1281,28,17)的形式
时间: 2024-03-22 19:38:26 浏览: 19
你可以使用Python的字符串操作来实现这个转换。首先,你可以使用`split()`方法将原始字符串按照逗号分割成一个列表,然后再通过列表索引来取得每个数值。接下来,你可以将这些数值拼接成一个新的字符串,使用逗号分隔。下面是一个示例代码:
```python
string = "Label: 2, Position: (1596, 1281), Size: 28 x 17"
label, position, size = string.split(", ")
x, y = position.strip("()").split(", ")
w, h = size.split(" x ")
new_string = f"{x}, {y}, {w}, {h}"
result = f"{label}, Position: ({new_string})"
print(result)
```
这个代码会输出以下结果:
```
Label: 2, Position: (1596, 1281, 28, 17)
```
注意,这个代码只能处理给定的字符串格式。如果字符串格式不同,可能需要对代码进行相应的修改。
相关问题
Label: 2, Position: (1596, 1281), Size: 28 x 17 Label: 3, Position: (1578, 1286), Size: 25 x 18改为(1596,1281,28,17)的形式
这里有两个字符串需要转换,你可以使用循环来处理它们。下面是一个示例代码:
```python
strings = ["Label: 2, Position: (1596, 1281), Size: 28 x 17", "Label: 3, Position: (1578, 1286), Size: 25 x 18"]
new_strings = []
for string in strings:
label, position, size = string.split(", ")
x, y = position.strip("()").split(", ")
w, h = size.split(" x ")
new_string = f"{x}, {y}, {w}, {h}"
new_strings.append(f"{label}, Position: ({new_string})")
result = " ".join(new_strings)
print(result)
```
这个代码会输出以下结果:
```
Label: 2, Position: (1596, 1281, 28, 17) Label: 3, Position: (1578, 1286, 25, 18)
```
注意,这个代码假设输入的字符串格式都相同。如果输入的字符串格式不同,可能需要对代码进行相应的修改。
<view> 详细地址: </view>为这个wxml 的 class添加类似于elementUI中 tag标签的样式,需要占有实际的位置,不能因为position属性导致遮挡其他的标签内容
你可以使用伪元素 `::before` 或 `::after` 来实现类似于 elementUI 中 tag 标签的样式,同时不会影响其他标签的位置。具体实现方法如下:
1. 首先给 `<view>` 标签添加一个类名,例如 `address-label`。
2. 在 CSS 中,使用 `position: relative;` 来让 `<view>` 标签成为定位上下文。
3. 使用 `::before` 或 `::after` 伪元素来添加标签样式,并设置它们的 `position` 属性为 `absolute`,这样它们就可以脱离文档流,并且相对于 `<view>` 标签进行定位。
4. 给伪元素设置 `top` 和 `left` 属性来控制它们的位置,并且使用 `transform: translate(-50%, -50%);` 来使它们相对于父元素水平垂直居中。
5. 最后,给伪元素添加样式,例如背景色、边框等。
示例代码如下:
```html
<view class="address-label">详细地址:</view>
```
```css
.address-label {
position: relative;
}
.address-label::before {
content: "标签名";
position: absolute;
top: 50%;
left: 0;
transform: translate(-50%, -50%);
padding: 4px 8px;
background-color: #eee;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 12px;
font-weight: bold;
color: #333;
}
```
你可以根据需要修改伪元素的样式,例如调整位置、颜色、字体大小等。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)