字符串中的分隔值 [英] Separated value in string

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

问题描述

大家好,

我正在编写一个代码,该代码从配置设置文件(* .ini)中获取值.

这是我在* .ini中拥有的商品的示例:

Hi all,

I''m writing a code which get value from configuration settings file (*.ini)

Here are the sample of item that I have in the *.ini:

[MERCHANT]
SPLITTER=,
MERCH1=1,P,PAYMENT
MERCH2=0,R,ROADTAX
MERCH3=1,S,SUMMON



我将使用以下代码检索此值:



I will retrieve this value using this code:

m_IniMainObj.CurrentSection = INI_SCREENCFG_SECT_MERCHANT
m_strSplitter=m_IniMainObj.GetStrVal(INI_SPLITTER_KEY,"-")
m_strMerch1 = m_IniMainObj.GetStrVal(INI_MERCHANT_1_KEY, String.Empty)
m_strMerch2 = m_IniMainObj.GetStrVal(INI_MERCHANT_2_KEY, String.Empty)
m_strMerch3 = m_IniMainObj.GetStrVal(INI_MERCHANT_3_KEY, String.Empty)




该值当前以字符串形式设置在m_strXXXXX中.但是我想读取一个字符串,想要用这个来分隔值:

(1,P,付款)
(布尔值,字符串,字符串)

因此我可以保留第一个逗号的值为True或False,第二个逗号的ID和第三个逗号的描述的值,并将其保存在声明中




The value is current set into m_strXXXXX as string. But I want to read the string an want to separated the value with this:

(1,P,PAYMENT)
(Boolean,String,String)

so I can hold the value whether it is True or False for 1st comma, ID for 2nd comma and description for 3rd comma and I want to save it in a declaration

Dim bVisible as Boolean 'To hold 1st comma value (Boolean)
Dim strID as String 'To hold 2nd comma value (String)
Dim strDesc as String 'To hold 3r comma value (String)




有人可以帮帮我吗?很抱歉,如果我的问题很混乱,但是如果您有一定的权限,我将进行解释..




Can someone please help me? I''m sorry if my question is quite messy but if you have some clearance, I will explain..

推荐答案

好的,我想我理解您的要求.

您已经从ini文件中获取了信息,但是想存储此信息以备将来使用?

Ok I think I understand what your asking about.

You have already got the information from your ini file, but want to store this info to do what you will with later?

Public Class Merchant
    Public bVisible As Boolean 'To hold 1st comma value (Boolean)
    Public strID As String 'To hold 2nd comma value (String)
    Public strDesc As String

    Public Sub New(ByVal p_visible As Boolean, ByVal p_id As String, ByVal p_desc As String)
        bVisible = p_visible
        strID = p_id
        strDesc = p_desc
    End Sub

End Class



这是保存单个商人详细信息的简单类.

您可以使用以下商家字典.



That is a simple class to hold the details of a single merchant.

You could use a dictionary of merchants as below.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim merchants As Dictionary(Of String, Merchant)

       merchants = New Dictionary(Of String, Merchant)()

       merchants.Add("MERCH1", New Merchant(True, "P", "PAYMENT")) 'MERCH1=1,P,PAYMENT
       merchants.Add("MERCH2", New Merchant(False, "R", "ROADTAX")) 'MERCH2=0,R,ROADTAX
       merchants.Add("MERCH3", New Merchant(True, "S", "SUMMON")) 'MERCH3=1,S,SUMMON

       Dim merch3 As Merchant = merchants("MERCH3")
       MsgBox(merch3.strDesc)

   End Sub



您可以看到这种方式,您只需要告诉商人词典您要处理的商人即可.

希望这会有所帮助!



You can see that way you just need to tell the Dictionary of Merchants which Merchant you want to deal with.

Hope this helps!


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

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