从字符串中删除最后一个字符 [英] Remove the last character from a string

查看:85
本文介绍了从字符串中删除最后一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从字符串中删除最后一个字符的最快方法是什么?

What is fastest way to remove the last character from a string?

我有一个像这样的字符串

I have a string like

a,b,c,d,e,

我想删除最后一个','并取回剩下的字符串:

I would like to remove the last ',' and get the remaining string back:

OUTPUT: a,b,c,d,e

最快的方法是什么?

推荐答案

首先,我尝试不带空格rtrim($arraynama, ",");并得到错误结果.

First, I try without a space, rtrim($arraynama, ","); and get an error result.

然后我添加一个空格并获得良好的结果:

Then I add a space and get a good result:

$newarraynama = rtrim($arraynama, ", ");

这篇关于从字符串中删除最后一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆