如何在连字符之前拆分字符串 [英] How to split string before hyphen

查看:75
本文介绍了如何在连字符之前拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我的数据库中有以下ID:



ID

BK-01-10

BK-01-20

BK-01-30



我只需要获得:

10

20

$



请帮助我:)

Hi guys!

I have the following ID in my database:

ID
BK-01-10
BK-01-20
BK-01-30

and I need to get only:
10
20
30

Help me please :)

推荐答案

C#
stringCutted = myString.Split('-').Last();



SQL


SQL

SELECT SUBSTRING( ID , LEN(ID) -  CHARINDEX('-',REVERSE(ID)) + 2  , LEN(ID) ) FROM SAMPLE;



这里SAMPLE是表名。


Here SAMPLE is the table name.


List<string> lstIDs = new List<string>() { "BK-01-10", "BK-01-20", "BK-01-30" };
                foreach(string thisID in lstIDs)
                {
                    Console.WriteLine(thisID.Substring(thisID.LastIndexOf("-")+1));
                }
            Console.ReadKey();


string [] IDs = issueField.split( - );

string [] distinctIDs = s.Distinct()。ToArray();
string[] IDs = issueField.split("-");
string[] distinctIDs = s.Distinct().ToArray();


这篇关于如何在连字符之前拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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