> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xray.cool/llms.txt
> Use this file to discover all available pages before exploring further.

# format

> `format`函数主要用于格式化字符串，可以通过指定的对齐字符、前缀以及步进参数来调整字符串的显示样式。

## 函数原型

`func (data string) format(align int, align_data string, prefix string, step int) string`

### 参数介绍

| 参数名称        | 参数介绍                                                 |
| ----------- | ---------------------------------------------------- |
| data        | 待格式化的原始字符串                                           |
| align       | 在每个步进区间内，每两个字符之间的`align_data`填充数量，实际填充数量为`align - 1` |
| align\_data | 用于填充对齐的单字符                                           |
| prefix      | 每个步进之前添加的前缀字符串                                       |
| step        | 步进，控制每隔多少字符进行一次格式化操作，然后插入`prefix`和使用`align_data`填充   |

## 举例

| 原始字符串     | 调用语句                               | 输出结果                   |
| --------- | ---------------------------------- | ---------------------- |
| `'01234'` | `'01234'.format(2, '0', '\\x', 1)` | `\x00\x01\x02\x03\x04` |
| `'abcde'` | `'abcde'.format(2, ' ', '-', 2)`   | `- a b- c d- e`        |
| `'hello'` | `'hello'.format(1, '_', '>', 2)`   | `>he>ll>o`             |
| `'data'`  | `'data'.format(3, '.', '#', 2)`    | `#d.a#t.a`             |
