如何从组合框字符串中获取特定值 [英] How to fetch a specific value from a combo box string

查看:68
本文介绍了如何从组合框字符串中获取特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我的表格我正在从记事本文件中填写一个combox

组合框包含的值如C:\\ \\Application\SSS0001



最后一部分即SSS0001是公司代码



现在点击保存按钮点击我必须检查该特定公司的用户名和密码。



所以我想减少组合框的值并提取公司代码然后进行比较。



请告诉我该怎么做..如果您觉得还有其他任何方式请告诉我们..



谢谢你

解决方案

你分裂了字符串(参见String.Split [ ^ ])使用字符 \ 作为分隔符并获取结果数组的最后一项。


首先获取组合框的选定值,从字符串中获取最后一次出现''\''的索引然后获得所需的子字符串。即:



  Dim  cmbval < span class =code-keyword> As   String  
Dim compcode < span class =code-keyword> As String
Dim lastPos < span class =code-keyword>作为 整数

cmbval = C:\ Application \ SSS0001 ' me.cmbbox.selectedvalue,这是你的组合框中的值
lastPos = cmbval.LastIndexOf( \' 从组合值中获取最后一次'\'的位置
compcode = cmbval.Substring(lastPos + 1 ' 在lastPos之后获取子字符串
MsgBox(compcode)' out put


根据您的要求

试试这个

  string  str =  @  C:\ Application \ SSS0001; 
str = str.Split(' \\')[str.Split( ' \\')。长度 - 1 < /跨度>]; // 每次都会占用最后一个值。


// 或者您也可以使用以下内容
string str = @ C:\ Application \ SSS0001;
str = Path.GetFileName(str); // 它还将返回最后一个值(\ )


Hi all

I my form i am filling a combox from a notepad file
the combo box contains values like C:\Application\SSS0001

the last part i.e. SSS0001 is company code

Now on the save button click i have to check the username, password for that particular company.

so i want to cut the value of the combo box and extract the company code and then compare .

Please tell me how to do this..or if you feel there is any other way please tell..

Thank you

解决方案

You migh split the string (see String.Split[^]) using the character \ as separator and take the last item of the resulting array.


At first take selected value of your combobox, get index of last occurrence of ''\'' from string and then get desired substring .That is :

Dim cmbval As String
        Dim compcode As String
        Dim lastPos As Integer

        cmbval = "C:\Application\SSS0001" 'me.cmbbox.selectedvalue that is the value from your combo box
        lastPos = cmbval.LastIndexOf("\")  'get position of  last occurrence of '\' from combo value
        compcode = cmbval.Substring(lastPos + 1)  'get substring after lastPos
        MsgBox(compcode) 'out put


According to your requirements
Try this

string str = @"C:\Application\SSS0001";
            str = str.Split('\\')[str.Split('\\').Length - 1];      // it will take last value each time.


//or you can use following also
string str = @"C:\Application\SSS0001";
str = Path.GetFileName(str);// it will also return last value after last (\)


这篇关于如何从组合框字符串中获取特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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