Hey all,
Let's say I have a textfile with 'marked' values in it, for example,
something like this:
Name......... *name*
Street......... *street*
Email.......... *email*
And say I have 1 or more objects with properties equal to the name of those
marked values, for example:
Person.name, Person.street, Person.email
well you get the idea :)
Now, I want to replace the * * values in the textfile with the properties of
the object. Of course this ain't a problem, however, I do NOT want the
following situation:
//Search the file for a * * string
switch(strToRep lace)
{
case "*name*":
// replace strToReplace with Person.name
break;
case "*street*":
// replace strToReplace with Person.street
break;
// etc
}
this code just looks plain ugly to me and besides, if I get like 100+ * *
values in my (more than 1) textfiles, which is quite possible, this is a lot
of work too. I'm hoping for a very easy and clean way instead... is there a
way to call the corresponding property automatically when the names are
equal? Is there another way to do this? I've been looking for a solution
using design patterns but I couldn't find a good one, so I hope someone here
knows a good solution.
THanks a lot in advance,
Razzie 3 2104
Use a regular expression to perform the search. Once regex matches take the
string fragment u need and then add the prefix u want. Using the regex
avoids u creating the switch statement
Regards,
--
Angel J. Hernández M.
MCSD
"Razzie" <ra****@quickne t.nl> escribió en el mensaje
news:%2******** ********@tk2msf tngp13.phx.gbl. .. Hey all,
Let's say I have a textfile with 'marked' values in it, for example, something like this:
Name......... *name* Street......... *street* Email.......... *email*
And say I have 1 or more objects with properties equal to the name of
those marked values, for example:
Person.name, Person.street, Person.email
well you get the idea :) Now, I want to replace the * * values in the textfile with the properties
of the object. Of course this ain't a problem, however, I do NOT want the following situation:
//Search the file for a * * string switch(strToRep lace) { case "*name*": // replace strToReplace with Person.name break; case "*street*": // replace strToReplace with Person.street break; // etc }
this code just looks plain ugly to me and besides, if I get like 100+ * * values in my (more than 1) textfiles, which is quite possible, this is a
lot of work too. I'm hoping for a very easy and clean way instead... is there
a way to call the corresponding property automatically when the names are equal? Is there another way to do this? I've been looking for a solution using design patterns but I couldn't find a good one, so I hope someone
here knows a good solution.
THanks a lot in advance,
Razzie
Razzie wrote: Hey all,
Let's say I have a textfile with 'marked' values in it, for example, something like this:
Name......... *name* Street......... *street* Email.......... *email*
And say I have 1 or more objects with properties equal to the name of those marked values, for example:
Person.name, Person.street, Person.email
well you get the idea :) Now, I want to replace the * * values in the textfile with the properties of the object. Of course this ain't a problem, however, I do NOT want the following situation:
//Search the file for a * * string switch(strToRep lace) { case "*name*": // replace strToReplace with Person.name break; case "*street*": // replace strToReplace with Person.street break; // etc }
this code just looks plain ugly to me and besides, if I get like 100+ * * values in my (more than 1) textfiles, which is quite possible, this is a lot of work too. I'm hoping for a very easy and clean way instead... is there a way to call the corresponding property automatically when the names are equal? Is there another way to do this? I've been looking for a solution using design patterns but I couldn't find a good one, so I hope someone here knows a good solution.
This is a solution tailor made for reflection.
You can use regular expressions or custom search code to find the markers.
Then one you get the property name from the marker, use reflection to
find the value of that property and replace the marker with that value.
--
mikeb
So I guess I'll have to look for RegEx but especially reflection. Ok thanks
all!
"Razzie" <ra****@quickne t.nl> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. Hey all,
Let's say I have a textfile with 'marked' values in it, for example, something like this:
Name......... *name* Street......... *street* Email.......... *email*
And say I have 1 or more objects with properties equal to the name of those marked values, for example:
Person.name, Person.street, Person.email
well you get the idea :) Now, I want to replace the * * values in the textfile with the properties of the object. Of course this ain't a problem, however, I do NOT want the following situation:
//Search the file for a * * string switch(strToRep lace) { case "*name*": // replace strToReplace with Person.name break; case "*street*": // replace strToReplace with Person.street break; // etc }
this code just looks plain ugly to me and besides, if I get like 100+ * * values in my (more than 1) textfiles, which is quite possible, this is a lot of work too. I'm hoping for a very easy and clean way instead... is there a way to call the corresponding property automatically when the names are equal? Is there another way to do this? I've been looking for a solution using design patterns but I couldn't find a good one, so I hope someone here knows a good solution.
THanks a lot in advance,
Razzie
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Janey |
last post by:
I want to be able to strip any character that is does not appear in
the following list from a text string:
$LegalChars="\"!#$%&'()*+,-.\\/0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~";
And conververt the following:
£ to £
€ to €
‘ to '
' to '
|
by: yaipa |
last post by:
What would be the common sense way of finding a binary pattern in a
..bin file, say some 200 bytes, and replacing it with an updated pattern
of the same length at the same offset?
Also, the pattern can occur on any byte boundary in the file, so
chunking through the code at 16 bytes a frame maybe a problem. The
file itself isn't so large, maybe 32 kbytes is all and the need for
speed is not so great, but the need for accuracy in the...
|
by: Dimitris Georgakopuolos |
last post by:
Hello,
I have a text file that I load up to a string. The text includes
certain expression like {firstName} or {userName} that I want to match
and then replace with a new expression. However, I want to use the
text included within the brackets to do a lookup so that I can replace
the expression with the new text.
For example:
|
by: J.S. |
last post by:
Let's say I have a text file with parameters like the following embedded in
the text:
@@Textbox1@@, @@Textbox2@@, etc.
Is it possible to replace the parameters in the text file with values
entered into textboxes in the Windows Forms UI?
Thanks,
J.S.
|
by: anonymous |
last post by:
Hello,
I need to replace this char  with another char.
However I am not able to acieve this. I tried this but it
doesnt work:
str = str.Replace(chr(asc(194)), "")
Can somebody help ?
| |
by: Adam J. Schaff |
last post by:
I am writing a quick program to edit a binary file that contains file paths
(amongst other things). If I look at the files in notepad, they look like:
<gibberish>file//g:\pathtofile1<gibberish>file//g:\pathtofile2<gibberish>
etc.
I want to remove the "g:\" from the file paths. I wrote a console app that
successfully reads the file and writes a duplicate of it, but fails for some
reason to do the "replacing" of the "g:\". The code...
|
by: J.S. |
last post by:
I have a text file with parameters like the following embedded in the text:
@@TextBox1@@, @@TextBox2@@, etc.
I know how to read this text file. However, I am trying to figure out how
to replace these parameters in the text file with values of the textboxes on
my Windows Form called Form1. For example, replace @@TextBox1@@ with value
of TextBox1, replace @@TextBox2@@ with value of TextBox2, replace
@@ComboBox1@@ with value of...
|
by: FireHead |
last post by:
Hello C World & Fanatics
I am trying replace fgets and provide a equavivalant function of
BufferedInputReader::readLine.
I am calling this readLine function as get_Stream.
In the line 4 where default_buffer_length is changed from 4 --24 code
works fine.
But on the same line if I change the value of default_buffer_length
from 4 --10 and I get a memory error.
And if the change the value of the same variable from 4 --1024 bytes;
|
by: saif.shakeel |
last post by:
Hi,
I need to replace a string in xml file with something else.Ex
- <SERVICEPARAMETER id="_775" Semantics="subfunction" DDORef="_54">
<SHORTNAME>rate</SHORTNAME>
<LONGNAME>rate</LONGNAME>
<VALUE role="constant" DataType="unsigned" value="1" />
<BYTEPOSITION role="position" BytePos="1" />
</SERVICEPARAMETER>
- <SERVICEPARAMETER id="_776" Semantics="localId" DDORef="_54">
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |