在字符串中填写字段占位符? [英] Form field place holders in strings?

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

问题描述

如果我在数据集表格列中有以下文字:此协议

确定{BandName}将在{StartTime}和
$ b $之间的{EventDate}上播放b {EndTime} ...然后,我将如何获取字段名称{BandName},{StartTime},

{EndTime}和{EventDate},将它们与实际数据集表格列匹配

名称,并在最终的

页面输出中显示实际值而不是占位符?我知道这可能需要一些字符串解析和

的东西,但我需要一些好方向。另一件事就是这个完整的东西是完全动态的。我事先不知道任何文本或占位符

名称(或表列名称)。这些表单正在从向导控件创建

(包括使用的表单字段)。关于

的任何想法从哪里开始?

If I have the following text in a dataset table column: "This agreement
establishes that {BandName} will play on {EventDate} between {StartTime} and
{EndTime}..." How would I then take the field names {BandName}, {StartTime},
{EndTime} and {EventDate}, match them up with actual dataset table column
names, and show the actual values instead of the placeholders on the final
page output? I know this would probably require some string parsing and
stuff, but I need some good direction here. The other thing is that this
whole thing is totally dynamic. I wont know any of the text or placeholder
names (or table column names) in advance. These forms are being creating
from a wizard control (including what form fields are used). Any ideas on
where to get started?

推荐答案

让我们假设你已经被提取了'''''''''''''''''''''''''''''''''''''''''''''''''''$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ >

1.可能有一个或多个令牌以{开头}结尾。


2.每个令牌的内部部分是数据行中的一列。


首先,将标记的内部部分提取到一个字符串数组中。


然后,删除所有不需要的文本从每个元素中取代_displaytext中的令牌

,使用数据行中相关列中的文本。

忽略任何不包含令牌的元素:


Dim _ss As String()= _displaytext.Split(" {" c)


For _i As Integer = 0 To _ss.Length - 1

如果_ss(_i).Contains("}")则

_ss(_i)= _ss(_i).Substring(0,_ss(_ i).IndexOf("}"))

_displaytext = _displayText.Replace(" ; {" &安培; _ss(_i)& "}",

_datarow(_ss(_i))。ToString())

结束如果

下一页
<分拆后,_ss的元素是:

此协议规定

BandName}将在

上播放EventDate}

StartTime}和

EndTime} ...


在循环中,第一个元素将被忽略,因为它不包含

令牌。其他4个元素每个都以一个标记开头,因为它们包含一个}。


If ... Then ... End If块中的第一个语句剥离}和所有

来自令牌的以下文字,以便感兴趣的4个元素成为:

BandName

EventDate

StartTime
EndTime


If ... Then ... End If块中的第二个语句用_displaytext中的令牌替换

您的数据行中的值。请注意,{

和}必须包含在替换中以使其正常工作。


您必须处理一些问题,其中一些是:


区分大小写:令牌的名称必须与

的名称完全匹配,包括套管。


如果datarow的值需要进一步格式化,

例如日期,时间,数字等怎么办?


如果数据行中的值是空白还是DbNull?


这些是修辞问题,但它们是你必须考虑的事情。


我所呈现的内容不是通过任何方式做到这一点的唯一方式,但是

给你一个起点。

" Andy B" < a _ ***** @ sbcglobal.netwrote in message

news:eo ************** @ TK2MSFTNGP04.phx.gbl ...
Lets'' start with the assumption that you have ''extracted'' the ''display'' text
into a string variable called, say, _displaytext.

There are 2 things that you know.

1. There may be 1 or more tokens that startwith { and end with }.

2. The inner portion of each token is the name of a column in your datarow.

First, extract inner portion of the tokens into a String array.

Then, remove all the unwanted text from each element and replace the token
in _displaytext with the text from the relevant column from your datarow.
Ignore any elements that do not contain a token:

Dim _ss As String() = _displaytext.Split("{"c)

For _i As Integer = 0 To _ss.Length - 1
If _ss(_i).Contains("}") Then
_ss(_i) = _ss(_i).Substring(0, _ss(_i).IndexOf("}"))
_displaytext = _displayText.Replace("{" & _ss(_i) & "}",
_datarow(_ss(_i)).ToString())
End if
Next

After the split, the ellements of _ss are:
This agreement establishes that
BandName} will play on
EventDate} between
StartTime} and
EndTime}...

In the loop, the first element will be ignored because it doesn''t contain a
token. The other 4 elements each startwith a token because they contain a }.

The first statement in the If ... Then ... End If block strips the } and all
the following text from the token so that the 4 elements of interest become:
BandName
EventDate
StartTime
EndTime

The second statement in the If ... Then ... End If block replaces the token
in _displaytext with the required value from your datarow. Note that the {
and } must be included in the replace for it to work properly.

There are some issues that you will have to deal with, some of which are:

Case-sensitivity: The name for the token MUST match the name of
the column EXACTLY including casing.

What if the value from the datarow required further formatting,
e.g., dates, times, numbers etc.?

What if the value from the datarow is blank or DbNull?

These are rhetorical questions but they are things you must consider.

What I have presented in not the only way of doing it by any means but it
gives you a starting point.
"Andy B" <a_*****@sbcglobal.netwrote in message
news:eo**************@TK2MSFTNGP04.phx.gbl...

如果我在数据集表格列中有以下文字:此协议

确定{BandName}将在{EventDate}之间播放{StartTime}

和{EndTime} ......然后,我如何获取字段名称{BandName},

{StartTime},{EndTime}和{EventDate},将它们与实际数据集匹配

表列名,并在最终页面输出中显示实际值而不是占位符

?我知道这可能需要一些字符串

解析和东西,但我需要一些好方向。另一件事是

这整个事情是完全动态的。我事先不知道任何文本或

占位符名称(或表列名称)。这些表单是从向导控件创建的(包括使用的表单字段是/ b
)。关于从哪里开始的任何想法?
If I have the following text in a dataset table column: "This agreement
establishes that {BandName} will play on {EventDate} between {StartTime}
and {EndTime}..." How would I then take the field names {BandName},
{StartTime}, {EndTime} and {EventDate}, match them up with actual dataset
table column names, and show the actual values instead of the placeholders
on the final page output? I know this would probably require some string
parsing and stuff, but I need some good direction here. The other thing is
that this whole thing is totally dynamic. I wont know any of the text or
placeholder names (or table column names) in advance. These forms are
being creating from a wizard control (including what form fields are
used). Any ideas on where to get started?


Andy,


因为这是我的问题而且它是很简单就像你展示它一样,然后我会用b $ b来制作3个替换语句。


TheText = TheText.Replace(" {BandName}",TheBandName)

等,另外两个。


Cor

" Andy B" < a _ ***** @sbcglobal.netschreef in bericht

news:eo ************** @ TK2MSFTNGP04.phx.gbl ...
Andy,

As it was my problem and it was as simple like you show it, then I would
make 3 replace statements.

TheText = TheText.Replace("{BandName}",TheBandName)
etc, for the other two.

Cor
"Andy B" <a_*****@sbcglobal.netschreef in bericht
news:eo**************@TK2MSFTNGP04.phx.gbl...

如果我在数据集表格列中有以下文字:此协议

确定{BandName}将在{EventDate}之间播放{StartTime}

和{EndTime} ......然后,我如何获取字段名称{BandName},

{StartTime},{EndTime}和{EventDate},将它们与实际数据集匹配

表列名,并在最终页面输出中显示实际值而不是占位符

?我知道这可能需要一些字符串

解析和东西,但我需要一些好方向。另一件事是

这整个事情是完全动态的。我事先不知道任何文本或

占位符名称(或表列名称)。这些表单是从向导控件创建的(包括使用的表单字段是/ b
)。关于从哪里开始的任何想法?
If I have the following text in a dataset table column: "This agreement
establishes that {BandName} will play on {EventDate} between {StartTime}
and {EndTime}..." How would I then take the field names {BandName},
{StartTime}, {EndTime} and {EventDate}, match them up with actual dataset
table column names, and show the actual values instead of the placeholders
on the final page output? I know this would probably require some string
parsing and stuff, but I need some good direction here. The other thing is
that this whole thing is totally dynamic. I wont know any of the text or
placeholder names (or table column names) in advance. These forms are
being creating from a wizard control (including what form fields are
used). Any ideas on where to get started?


再次阅读Andy的倒数第二句!


" Cor Ligthert [MVP]" < no ************ @ planet.nlwrote in message

news:67 ****************** **************** @ microsof t.com ...
Read Andy''s penultimate sentence again!

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:67**********************************@microsof t.com...

Andy,


因为这是我的问题,就像你展示它一样简单,然后我会

制作3个替换语句。


TheText = TheText .Replace(" {BandName}",TheBandName)

等,另外两个。


Cor


Andy B < a _ ***** @sbcglobal.netschreef in bericht

news:eo ************** @ TK2MSFTNGP04.phx.gbl ...
Andy,

As it was my problem and it was as simple like you show it, then I would
make 3 replace statements.

TheText = TheText.Replace("{BandName}",TheBandName)
etc, for the other two.

Cor
"Andy B" <a_*****@sbcglobal.netschreef in bericht
news:eo**************@TK2MSFTNGP04.phx.gbl...

>如果我在数据集表格列中有以下文字:此协议确定{BandName}将在{StartDate}之间{StartDate}播放}
和{EndTime} ......然后,我将如何获取字段名称{BandName},
{StartTime},{EndTime}和{EventDate},将它们与实际数据集
表列名称匹配,并显示实际值而不是
占位符在最终页面输出?我知道这可能需要一些字符串解析和东西,但我需要一些好的方向。另外一件事是,整个事情是完全动态的。我事先不知道任何文本或占位符名称(或表格列名称)。
这些表单是从向导控件创建的(包括使用的形式
字段)。关于从哪里开始的任何想法?
>If I have the following text in a dataset table column: "This agreement
establishes that {BandName} will play on {EventDate} between {StartTime}
and {EndTime}..." How would I then take the field names {BandName},
{StartTime}, {EndTime} and {EventDate}, match them up with actual dataset
table column names, and show the actual values instead of the
placeholders on the final page output? I know this would probably require
some string parsing and stuff, but I need some good direction here. The
other thing is that this whole thing is totally dynamic. I wont know any
of the text or placeholder names (or table column names) in advance.
These forms are being creating from a wizard control (including what form
fields are used). Any ideas on where to get started?


这篇关于在字符串中填写字段占位符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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