473,472 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Form field place holders in strings?

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?
Jun 27 '08 #1
10 1197
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...
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?
Jun 27 '08 #2
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...
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?
Jun 27 '08 #3
Read Andy's penultimate sentence again!

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:67**********************************@microsof t.com...
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...
>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?
Jun 27 '08 #4
Stephany,

It is not worse then yours, if you don't know were New Zealand is, you
probably can go to Holland, Danmark, those two isles 2000 km east of
Australia or other place in the world.

Andy tells that he does not know anything, therefore I gave him a start as I
would start.

Although I often used IndexOf (kind of javascript background), I would not
use it here.

Cor

"Stephany Young" <noone@localhostschreef in bericht
news:e7**************@TK2MSFTNGP02.phx.gbl...
Read Andy's penultimate sentence again!

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:67**********************************@microsof t.com...
>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...
>>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?
Jun 27 '08 #5
You must have got some really bad grass today!

Since when have Holland, Danmrak (sic) been isles and since when have they
been 2000 Km east of Australia.

He stated very clearly that he does NOT know, at design-time, what the
tokens will be nor does he know, at design-time, the names of the columns in
the datatable that relate to the tokens.
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:28**********************************@microsof t.com...
Stephany,

It is not worse then yours, if you don't know were New Zealand is, you
probably can go to Holland, Danmark, those two isles 2000 km east of
Australia or other place in the world.

Andy tells that he does not know anything, therefore I gave him a start as
I would start.

Although I often used IndexOf (kind of javascript background), I would not
use it here.

Cor

"Stephany Young" <noone@localhostschreef in bericht
news:e7**************@TK2MSFTNGP02.phx.gbl...
>Read Andy's penultimate sentence again!

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:67**********************************@microso ft.com...
>>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...
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?

Jun 27 '08 #6
Ignoring your bad humor to day, he does not even know it there any {} in it,
so your solution does not work as well.

Otherwise it is of course Regex.

Cor

"Stephany Young" <noone@localhostschreef in bericht
news:uS**************@TK2MSFTNGP03.phx.gbl...
You must have got some really bad grass today!

Since when have Holland, Danmrak (sic) been isles and since when have they
been 2000 Km east of Australia.

He stated very clearly that he does NOT know, at design-time, what the
tokens will be nor does he know, at design-time, the names of the columns
in the datatable that relate to the tokens.
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:28**********************************@microsof t.com...
>Stephany,

It is not worse then yours, if you don't know were New Zealand is, you
probably can go to Holland, Danmark, those two isles 2000 km east of
Australia or other place in the world.

Andy tells that he does not know anything, therefore I gave him a start
as I would start.

Although I often used IndexOf (kind of javascript background), I would
not use it here.

Cor

"Stephany Young" <noone@localhostschreef in bericht
news:e7**************@TK2MSFTNGP02.phx.gbl...
>>Read Andy's penultimate sentence again!

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:67**********************************@micros oft.com...
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...
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?
>

Jun 27 '08 #7
It will work perfectly well if there are no tokens in it!
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:9A**********************************@microsof t.com...
Ignoring your bad humor to day, he does not even know it there any {} in
it, so your solution does not work as well.

Otherwise it is of course Regex.

Cor

"Stephany Young" <noone@localhostschreef in bericht
news:uS**************@TK2MSFTNGP03.phx.gbl...
>You must have got some really bad grass today!

Since when have Holland, Danmrak (sic) been isles and since when have
they been 2000 Km east of Australia.

He stated very clearly that he does NOT know, at design-time, what the
tokens will be nor does he know, at design-time, the names of the columns
in the datatable that relate to the tokens.
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:28**********************************@microso ft.com...
>>Stephany,

It is not worse then yours, if you don't know were New Zealand is, you
probably can go to Holland, Danmark, those two isles 2000 km east of
Australia or other place in the world.

Andy tells that he does not know anything, therefore I gave him a start
as I would start.

Although I often used IndexOf (kind of javascript background), I would
not use it here.

Cor

"Stephany Young" <noone@localhostschreef in bericht
news:e7**************@TK2MSFTNGP02.phx.gbl...
Read Andy's penultimate sentence again!

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:67**********************************@micro soft.com...
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.. .
>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?
>>
>

Jun 27 '08 #8
Cor Ligthert[MVP] wrote:
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

If you had a datarow and did not know the column names at design time, you could
loop through the columns, using the above as a template:

Private Sub FillFields(ByVal TheText As String, ByVal TheData As DataRow)
Dim DC As DataColumn

For Each DC In TheData.Table.Columns
TheText = TheText.Replace("{" + DC.ColumnName + "}",
TheData.Item(DC).ToString)
Next DC

End Sub

Jun 27 '08 #9
Hi.

I have a question related to your example steeve. How would you actually
determine if there are any {token} elements in the text of a particular text
string? What I have to do, is to go through all of the text sections and
determine if there are any token elements. If there are token elements,
replace them with the actual column values. We have this part covered so
far. If there are no token elements in the text strings, just append the
"form fields" that have been created already at the end of the string values
(like an attached form for a contract for service). Do you think this is a
good way of doing things? Or should I just create a whole other creation
wizard just for this type of form? I don't really know if there would be a
ton of overhead, since only 2 people will have access to this feature set
and it isn't expected to be used a whole lot as it is anyways. Tnx for the
help already given and the help in advance...
"Steve Gerrard" <my********@comcast.netwrote in message
news:I5******************************@comcast.com. ..
Cor Ligthert[MVP] wrote:
>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


If you had a datarow and did not know the column names at design time, you
could loop through the columns, using the above as a template:

Private Sub FillFields(ByVal TheText As String, ByVal TheData As DataRow)
Dim DC As DataColumn

For Each DC In TheData.Table.Columns
TheText = TheText.Replace("{" + DC.ColumnName + "}",
TheData.Item(DC).ToString)
Next DC

End Sub

Jun 27 '08 #10
If the strings are not too long, I see nothing wrong with doing something like
Dim TheOriginal As String = TheText

' do the substitution loop here...

' now see if it changed

If TheText = TheOriginal Then
' nothing was changed, do alternative
' perhaps another loop through,
' appending the field values instead:
TheText += vbCrLf + TheData.Item(DC).ToString
' or whatever you want/need
End If
Andy B wrote:
Hi.

I have a question related to your example steeve. How would you
actually determine if there are any {token} elements in the text of a
particular text string? What I have to do, is to go through all of
the text sections and determine if there are any token elements. If
there are token elements, replace them with the actual column values.
We have this part covered so far. If there are no token elements in
the text strings, just append the "form fields" that have been
created already at the end of the string values (like an attached
form for a contract for service). Do you think this is a good way of
doing things? Or should I just create a whole other creation wizard
just for this type of form? I don't really know if there would be a
ton of overhead, since only 2 people will have access to this feature
set and it isn't expected to be used a whole lot as it is anyways.
Tnx for the help already given and the help in advance...
"Steve Gerrard" <my********@comcast.netwrote in message
news:I5******************************@comcast.com. ..
>>
If you had a datarow and did not know the column names at design
time, you could loop through the columns, using the above as a
template: Private Sub FillFields(ByVal TheText As String, ByVal TheData As
DataRow) Dim DC As DataColumn

For Each DC In TheData.Table.Columns
TheText = TheText.Replace("{" + DC.ColumnName + "}",
TheData.Item(DC).ToString)
Next DC

End Sub

Jun 27 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael Brennan-White | last post by:
If I submit my for using a get action the resulting page loads . If I use a post action I get an error page saying "The page cannot be found". I am calling the originating page!!! This happens...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
5
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test...
15
by: simonmarkjones | last post by:
I want to validate my form using a BeforeUpdate event. However now that i call my code with a beforeupdate it wont let me go to next or previous records. What code should i put in o allow me...
5
0
by: Mark Rae | last post by:
Hi, I mainly use PayPal for eCommerce, but one of the features which I don't like is the fact that you pass shopping cart data to their payment gateway by means of hidden form variables, e.g. ...
17
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I get the value of a form control? -----------------------------------------------------------------------...
3
by: Rowan | last post by:
I'm trying to enter data from an array ( eg entry1=(x=>y,a=b), entry2=(x=>y,a=>c)) I'm trying to use place holders to dump the data. It maybe late but I can't get this to work. below is the actual...
2
by: Bob | last post by:
I am trying to obtain values of a submitted form when the form is inside a content placeholder via a master page. For example: <asp:content contentplaceholderid="contentMain" runat="server">...
1
by: Andy B | last post by:
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...
10
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
15
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.