Monday, March 26, 2012
Text File Processing
The problem that I am having is the starts with a 12 line header that I can through way because the first 12 line will always be the same. Where my problem is that at certain points during the file a sub set of the header file will occur. There does not seem to be any rhyme or reason as to where the entry occurs.
Does anyone have any idea how how to check for this line pattern and how I can ignore it?What I've done in cases like this is to import the file into anintermediary table, delete any rows which contain header information,and insert the remaining records into the final destination table.
Saturday, March 24, 2012
Text manipulation
Hi
Can someone please help me!? I'm trying to work out how to take text from a multiline asp:TextBox and find and replace the \r\n characters with equivalent HTML <p></p> tags. So that when it is retrieved from the database it can be displayed as correct HTML!
I'm not sure where to start really. I thought that if I did a replace on \r\n\r\n (I think thats what shows a paragraph) with </p><p> that would work. However that wouldn't pick up the beginning of the string, and would add a <p> tag at the end that would fail validation.
Also the reverse is true, if I wanted to put the text back into a textbox for editing, I wouldn't want the HTML to show?!
Please can someone point me in the right direction!
Many thanks
Ross
Hey Dude!
Did you try this:
string.Replace("\r\n","<br/>") ?
kcis8rm:
I'm not sure where to start really. I thought that if I did a replace on \r\n\r\n (I think thats what shows a paragraph) with </p><p> that would work. However that wouldn't pick up the beginning of the string, and would add a <p> tag at the end that would fail validation.
Also the reverse is true, if I wanted to put the text back into a textbox for editing, I wouldn't want the HTML to show?!
You would be better off using one of the free rich text editors. Otherwise \r\r should find a paragraph break, then you would have to manipulate the result of your Replace() operation to add <p> to the beginning, and remove <p> at the end.
Dude
Check this out, I just figured that link for you: http://www.phptr.com/articles/article.asp?p=29585&rl=1
may be it gonna help you to solve your problem, try it out and let me know if it works, else paste your code and we will work on it together.
Hi
Thanks for the help, I think I've now sorted it :-)
I've now sorted this, however you brought up and interesting point! Can you point me in the direction of some of these free rich text editors please?!
kcis8rm:
Hi
Thanks for the help, I think I've now sorted it :-)
Good. What did you do? It might be of interest to others who find this thread.
I solved it by using a regular expression to replace the pattern \r\n\r\n (which shows a paragraph) with the text </p><p> and then adding a <p> to the beginning of the string and a </p> to the end of the string!
Excellent. Any chance of marking my post as the answer then?
text manipulation
Senario: I'm retrieving some text from a database and when I display
this text on my page I want the first paragraph to be a different
color.
Do I need to break up the values i.e. find where <br><br> occurs and
substring up to this point. Then have two labels on the form??
or is there an easier method?
Thanks!
Jack"jack-e" <jack-b@.humlog.com> wrote in news:1123565399.992699.270660
@.g47g2000cwa.googlegroups.com:
> Hi,
> Senario: I'm retrieving some text from a database and when I display
> this text on my page I want the first paragraph to be a different
> color.
> Do I need to break up the values i.e. find where <br><br> occurs and
> substring up to this point. Then have two labels on the form??
Depending on how complex the search is, Regular expressions maybe a better
choice than substrings.
As for color coding, you can try:
-Style sheets, assign each paragraph to their own CSS class
-Rather than use two labels, you can just append some HTML to the database
text and place the results into a literal.
But in short, using two labels works just as well : )
--
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
do you know how would i use a regular expression to find when a
paragraph finishes? (or begins?)
"jack-e" <jack-b@.humlog.com> wrote in message
news:1123568497.239674.83420@.z14g2000cwz.googlegro ups.com...
> do you know how would i use a regular expression to find when a
> paragraph finishes? (or begins?)
Depends entirely on how the paragraphs are encoded. Earlier you implied
two consecutive <br> tags, for example. Whenever I write paragraphs in HTML,
I enclose them in <p> and </p>, so looking for two <br> tags would not work
with my data.
- Oliver.
Text Manipulation
I need it very soon to finish my project before sataerday.
Thank you in advance.
I want to develop a content management component that suits a blog or a
portal.
In it I develop an article authoring/browsing tool withwhich I do have a
problem.
When posting an Article, I want to replace each word like microsoft with
<a href=http://www.microsoft.com">Microsoft</a> where
http://www.microsoft.com is stored in the database. This is not a very big
problem I think especially using "foreach" in C#.
My real problem is tat I may provide the same word "Microsoft" as a part of
a URL liike
<a
href=http://www.microsoft.com/technet/community/scriptcenter/default.mspx">
Check out the new scripts in the TechNet Script Center </a>
or even an <asp:Hyperlink> ... In such cases, replacing the word "Microsoft"
is never wanted as it'll make a big problem to me.
How should I do that ?"Mohamed Ahmed Meligy" <xmastereg@.hotmail.com> wrote in message news:evNi9RHVEHA.4028@.TK2MSFTNGP09.phx.gbl...
> Can't anyone help me with this ?
> I need it very soon to finish my project before sataerday.
> Thank you in advance.
> I want to develop a content management component that suits a blog or a
> portal.
> In it I develop an article authoring/browsing tool withwhich I do have a
> problem.
> When posting an Article, I want to replace each word like microsoft with
> <a href=http://www.microsoft.com">Microsoft</a> where
> http://www.microsoft.com is stored in the database. This is not a very big
> problem I think especially using "foreach" in C#.
> My real problem is tat I may provide the same word "Microsoft" as a part of
> a URL liike
> <a
> href=http://www.microsoft.com/technet/community/scriptcenter/default.mspx">
> Check out the new scripts in the TechNet Script Center </a>
> or even an <asp:Hyperlink> ... In such cases, replacing the word "Microsoft"
> is never wanted as it'll make a big problem to me.
> How should I do that ?
Assuming that the text is html, so that a literal "<" is encoded (as <),
you can walk through the string, noting start (<) and finish (>) of tags.
Replace only in texts that are not tags.
The rest is left as an exercise for the reader :-)
Hans Kesting
text manipulation
Senario: I'm retrieving some text from a database and when I display
this text on my page I want the first paragraph to be a different
color.
Do I need to break up the values i.e. find where <br><br> occurs and
substring up to this point. Then have two labels on the form'
or is there an easier method?
Thanks!
Jack"jack-e" <jack-b@.humlog.com> wrote in news:1123565399.992699.270660
@.g47g2000cwa.googlegroups.com:
> Hi,
> Senario: I'm retrieving some text from a database and when I display
> this text on my page I want the first paragraph to be a different
> color.
> Do I need to break up the values i.e. find where <br><br> occurs and
> substring up to this point. Then have two labels on the form'
Depending on how complex the search is, Regular expressions maybe a better
choice than substrings.
As for color coding, you can try:
-Style sheets, assign each paragraph to their own CSS class
-Rather than use two labels, you can just append some HTML to the database
text and place the results into a literal.
But in short, using two labels works just as well : )
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
[url]http://members.ebay.com/aboutme/
do you know how would i use a regular expression to find when a
paragraph finishes? (or begins?)
"jack-e" <jack-b@.humlog.com> wrote in message
news:1123568497.239674.83420@.z14g2000cwz.googlegroups.com...
> do you know how would i use a regular expression to find when a
> paragraph finishes? (or begins?)
Depends entirely on how the paragraphs are encoded. Earlier you implied
two consecutive <br> tags, for example. Whenever I write paragraphs in HTML,
I enclose them in <p> and </p>, so looking for two <br> tags would not work
with my data.
- Oliver.
Text Manipulation
I need it very soon to finish my project before sataerday.
Thank you in advance.
I want to develop a content management component that suits a blog or a
portal.
In it I develop an article authoring/browsing tool withwhich I do have a
problem.
When posting an Article, I want to replace each word like microsoft with
<a href=http://www.microsoft.com">Microsoft</a> where
http://www.microsoft.com is stored in the database. This is not a very big
problem I think especially using "foreach" in C#.
My real problem is tat I may provide the same word "Microsoft" as a part of
a URL liike
<a
href=http://www.microsoft.com/technet/community/scriptcenter/default.mspx">
Check out the new scripts in the technet Script Center </a>
or even an <asp:Hyperlink> ... In such cases, replacing the word "Microsoft"
is never wanted as it'll make a big problem to me.
How should I do that ?"Mohamed Ahmed Meligy" <xmastereg@.hotmail.com> wrote in message news:evNi9RHVEHA.4028@.TK2MS
FTNGP09.phx.gbl...
> Can't anyone help me with this ?
> I need it very soon to finish my project before sataerday.
> Thank you in advance.
> I want to develop a content management component that suits a blog or a
> portal.
> In it I develop an article authoring/browsing tool withwhich I do have a
> problem.
> When posting an Article, I want to replace each word like microsoft with
> <a href=http://www.microsoft.com">Microsoft</a> where
> http://www.microsoft.com is stored in the database. This is not a very big
> problem I think especially using "foreach" in C#.
> My real problem is tat I may provide the same word "Microsoft" as a part o
f
> a URL liike
> <a
> href=http://www.microsoft.com/technet/community/scriptcenter/default.mspx"
> Check out the new scripts in the technet Script Center </a>
> or even an <asp:Hyperlink> ... In such cases, replacing the word "Microsof
t"
> is never wanted as it'll make a big problem to me.
> How should I do that ?
>
Assuming that the text is html, so that a literal "<" is encoded (as <),
you can walk through the string, noting start (< ) and finish (> ) of tags.
Replace only in texts that are not tags.
The rest is left as an exercise for the reader :-)
Hans Kesting