减去未知字符串 [英] Subtract unknown string

查看:68
本文介绍了减去未知字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个excel文件,其中的列填充了大量值。我想从字段中只提取名称,但问题是虽然excel格式相同,但公司的价值也不同......因为一家公司的excel列看起来如下



I have a excel file with a column populated with lots of values. I want to extract only the name from the field, but the problem is though the excel format is the same, the values differ from company to company... as one company's excel column looks as follow

Name S/N-ABC000ED0
Name Surname S/N-ABE00CD00





和另一家公司





and the other company

ABC/Name/00
CDF/Name/10





我需要在我的应用程序中考虑这两种格式,但我不知道如何编写这种方法





I need to account for both types of format in my application, But I Have no idea how to write this method

public static string CleanUp(string name)
{
....
....

return name
}





我只想检索NAME部分和姓氏(如果有的话)。但由于格式不同,我有点卡住



I just want to retrieve the NAME part and the Surname (if there is one). But with the format difference, I'm kinda stuck

推荐答案

如果这些是你唯一的两种格式,那么很容易:



If these are your only two formats then it's easy:

public static string CleanUp(string name)
{
    string result;

    string[] parts = name.Split('/');

    if(parts.Count == 2)
       result = parts[0].TrimRight('S'); //get rid of that 'S'
    else if (parts.Count == 3)
       result = parts[1];
    else
       result = "unable to parse";
 
    //The result will be a name or "unable to parse".  You will still have to parse for surname etc
    return result 
}


这篇关于减去未知字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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