首页 > 解决方案 > 在函数中用连字符连接字符串

问题描述

我试图在我的函数中硬编码一个连字符并返回字符串,但我无法构建语法。你们能帮我语法吗?

NES_Person_ComputeInternalName_Internal(GetValue("FirstName").String, GetValue("LastName").String, _
                            Getvalue(uid_dialogcountry_iso3456).string,GetValue("City").String, _dep, GetValue("personnelNumber").String )

我想要之间的连字符:

Getvalue(uid_dialogcountry_iso3456).string, GetValue("City").String

标签: vb.net

解决方案


假设NES_Person_ComputeInternalName_Internal简单地连接您的字符串(这可能是不正确的),您可以使用字符串插值以获得更好的可读性(以及一段略短的代码):

Dim myString As String = $"{GetValue("FirstName").String}{GetValue("LastName").String}{GetValue(uid_dialogcountry_iso3456).String}-{GetValue("City").String}{_dep}{GetValue("personnelNumber").String})

根据GetValue的行为,您甚至可以省略.String

Dim myString As String = $"{GetValue("FirstName")}{GetValue("LastName")}{GetValue(uid_dialogcountry_iso3456)}-{GetValue("City")}{_dep}{GetValue("personnelNumber")})

字符串插值很棒,因为它会为您插入插入变量的类型。但是,您无需对此表单进行任何格式化,因此如果需要,您需要包含.ToString({StandardOrPredefinedStringFormat}).


推荐阅读