将n个字符从字符串的前面移动到末尾 [英] Move n characters from front of string to the end

查看:112
本文介绍了将n个字符从字符串的前面移动到末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个简单的问题,但我找不到解决方案。我想首先,让我们说来自字符串的2个字母,并将它们移动到该字符串的末尾。因此,例如,OK12将变为12OK。

It seems like an easy problem, but i can't find solution. I want to take first, let's say 2 letters from string, and move them to the end of this string. So for example, OK12 would become 12OK.

编辑:到目前为止,我已经尝试将字符串关闭,然后将其添加到字符串的其余部分,但我在那里尝试了一个单行解决方案,如预定义函数或其他东西。

edit: So far i've tried cutting string off, then adding it to the rest of the string, but i tought there's a one-line solution for that, like predefined function or something.

推荐答案

"OK12".substr(2) + "OK12".substr(0,2)

Generic解决方案:

var result = str.substr(num) + str.substr(0, num);

直播演示

这篇关于将n个字符从字符串的前面移动到末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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