简体   繁体   中英

Return the characters after Nth character in a string

I need help! Can someone please let me know how to return the characters after the nth character?

For example, the strings I have is "001 baseball" and "002 golf", I want my code to return baseball and golf, not the number part. Since the word after the number is not always the same length, I cannot use = Right(String, n)

Any help will be greatly appreciated

If your numbers are always 4 digits long:

=RIGHT(A1,LEN(A1)-5) //'0001 Baseball' returns Baseball

If the numbers are variable (ie could be more or less than 4 digits) then:

=RIGHT(A1,LEN(A1)-FIND(" ",A1,1)) //'123456 Baseball’ returns Baseball

Mid(strYourString, 4) (即没有可选的长度参数)将返回从第 4 个字符开始到字符串末尾的子字符串。

或者,您可以使用空格作为分隔符执行 Text to Columns。

Since there is the [vba] tag, split is also easy:

str1 = "001 baseball"
str2 = Split(str1)

Then use str2(1).

另一个公式选项是使用 REPLACE 函数将前 n 个字符替换为空,例如,如果 n = 4

=REPLACE(A1,1,4,"")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM