Re: Form field place holders in strings?
- From: "Stephany Young" <noone@localhost>
- Date: Mon, 16 Jun 2008 00:58:44 +1200
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_borka@xxxxxxxxxxxxx> wrote in message news:eo1AUTtzIHA.4876@xxxxxxxxxxxxxxxxxxxxxxx
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?
.
- References:
- Form field place holders in strings?
- From: Andy B
- Form field place holders in strings?
- Prev by Date: Re: XML Comment Screwed - Possibly a bug in VB??
- Next by Date: Re: XML Comment Screwed - Possibly a bug in VB??
- Previous by thread: Form field place holders in strings?
- Next by thread: Re: Form field place holders in strings?
- Index(es):
Relevant Pages
|