PHP--str_pad()函数用法

str_pad --  Pad a string to a certain length with another string

Description

string str_pad ( string input, int pad_length [, string pad_string [, int pad_type]])

This functions returns the input string padded on the left, the right, or both sides to the specified padding length. If the optional argument pad_string is not supplied, the input is padded with spaces, otherwise it is padded with characters from pad_string up to the limit.

Optional argument pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH. If pad_type is not specified it is assumed to be STR_PAD_RIGHT.

If the value of pad_length is negative or less than the length of the input string, no padding takes place.

例子 1. str_pad() example

<?php
$input = "Alien";
print str_pad($input, 10);                      // produces "Alien     "
print str_pad($input, 10, "-=", STR_PAD_LEFT);  // produces "-=-=-Alien"
print str_pad($input, 10, "_", STR_PAD_BOTH);   // produces "__Alien___"
?>

 

 

补齐字符串的长度.以pad_string 补.

要改变rt_kprintf函数输出的设备,需要修改底层输出函数的实现。具体步骤如下: 1. 找到rt_kprintf函数的定义,通常在rtthread/include/rtthread.h中。 2. 查看rt_kprintf函数的实现,通常是通过调用rt_kprintf_internal函数实现输出。 3. 找到rt_kprintf_internal函数的定义,通常在rtthread/libcpu/arm/cortex-mx/rt_kprintf.c中。 4. 修改rt_kprintf_internal函数中的输出函数,比如将其改为输出到指定的串口设备。 例如,如果要将输出改为输出到串口1,则可以按照以下步骤进行修改: 1. 打开rt_kprintf.c文件,找到rt_kprintf_internal函数的定义。 2. 找到以下代码: #ifdef RT_USING_FINSH if (rt_thread_self() && rt_thread_self()->parent != &tid0) { rt_sprintf(buffer, "%s", str); finsh_send_data(buffer, strlen(buffer)); return; } #endif /* RT_USING_FINSH */ rt_hw_console_output(str); 这里的rt_hw_console_output函数就是实现底层输出的函数,它可以输出到串口设备或者其他设备。 3. 将rt_hw_console_output函数修改为输出到串口1的函数,比如: extern void rt_hw_usart_send(char ch); void rt_hw_console_output(const char *str) { char ch; while ((ch = *str++) != '\0') { rt_hw_usart_send(ch); } } 这里的rt_hw_usart_send函数就是输出到串口1的函数。 4. 重新编译并下载程序,就可以将输出改为输出到串口1了。 需要注意的是,修改底层输出函数可能会影响其他代码的输出,因此需要谨慎修改。建议先在测试代码中进行修改和测试,确认正确后再应用到实际项目中。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值