|
Hi everybody,
I got a big problem dealing with regular expression, I want to extract the text between the body Tag (<body>…</body>) from a html document
I’m using this code
string [] strTabBody; // table containing Body message in case of many Body tag
string sContenu ; // Html returned without Body tag
MatchCollection MatchCase;
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled;
// regular expression to represent the body tag
Regex regSeparBody = new Regex(@"</?(?i:body)(.|\n)*?>*.</?(?i:body)(.|\n)*?>",options);
if(regSeparBody.IsMatch(sContenu))
{
MatchCase = regSeparBody.Matches(sContenu);
sContenu =MatchCase[0].Value.ToString();
}
return sContenu;
the problem is with this kind of text.
String IN:
"<BODY bgColor=#ffffff><DIV> </DIV><DIV style=\"FONT: 10pt arial\">----- Original Message ----- </DIV></BODY>"
String OUT:
"f<DIV> </DIV><DIV style=\"FONT: 10pt arial\">----- Original Message ----- </DIV>"
-->the f charachter musn’t be in my output string
Can anyone correct my regular expression ??
Thanks!!
-- modified at 8:13 Tuesday 16th January, 2007
|
|
|
|
|
I think the formatting has eliminated the regular expression. Try placing it in a pre tag or click the ignore html checkbox.
|
|
|
|
|
it's done! this is the regular expression:
Regex regSeparBody = new Regex(@"</?(?i:body)(.|\n)*?>*.</?(?i:body)(.|\n)*?>",options);
|
|
|
|
|
The following should give you what you are looking for:
string HeadText = Regex.Replace(HTMLText, @"</?(?i:body)(.|\n)*?>(?<inner_text>.*)</?(?i:body)(.|\n)*?>", "<inner_text>");
HTMLText is the full html text.
|
|
|
|
|
When I use a System.Drawing.Font object in a multithreaded environment, I get a InvalidOperationException when I try to add it to a font-collection.
I'm writing a program that generates pdf documents based on a pdflibrary. Every document is generated in a singlethreadapartment. To add text with a certain font to the document, I have to create a font object and add it to the font-collection of the document:
<br />
string _font = elem.GetAttribute("Font");
int fontSize = Int32.Parse(elem.GetAttribute("FontSize"));<br />
Font _f = new Font(_font, fontSize);<br />
font = page.Fonts.Add(_f);
As long as I have only one thread running, it works fine, but when I start two or more threads, an InvalidOperationException is thrown in the line
font = page.Fonts.Add(_f);
The code that starts a thread to generate a pdf:
Thread thread = new Thread(new ThreadStart(convert));
thread.SetApartmentState(ApartmentState.STA);<br />
thread.Start();
VisualStudio also proposes to "call the Release-HDC-method, when you use the graphicobejct after the gethdf-method".
Can you help me how to use the font object in the context above to avoid the Excption?
this is the whole error message:
System.InvalidOperationException wurde nicht behandelt.<br />
Message="Das Objekt wird bereits an anderer Stelle verwendet."<br />
Source="System.Drawing"<br />
StackTrace:<br />
bei System.Drawing.Graphics.get_DpiX()<br />
bei Syncfusion.Pdf.Implementation.Objects.Fonts.PDFTrueTypeFont.RecreateFont()<br />
bei Syncfusion.Pdf.Implementation.Objects.Fonts.PDFTrueTypeFont.Initialize(PDFDocument document)<br />
bei Syncfusion.Pdf.Implementation.Collections.PDFFontCollection.Add(IPDFFont font)<br />
bei Syncfusion.Pdf.Implementation.Collections.PDFFontCollection.Add(Font font, Boolean embbed)<br />
bei Syncfusion.Pdf.Implementation.Collections.PDFFontCollection.Add(Font font)<br />
bei Report_Generator.ReportGenerator.generatePDFReport() in C:\WINXP\Profiles\Hans-Peter\Eigene Dateien\Visual Studio 2005\Projects\Essential Studio\Report Generator\Report Generator\ReportGenerator.cs:Zeile 252.<br />
bei Report_Generator.ReportGenerator.start() in C:\WINXP\Profiles\Hans-Peter\Eigene Dateien\Visual Studio 2005\Projects\Essential Studio\Report Generator\Report Generator\ReportGenerator.cs:Zeile 135.<br />
bei Report_Generator.Form1.convert() in C:\WINXP\Profiles\Hans-Peter\Eigene Dateien\Visual Studio 2005\Projects\Essential Studio\Report Generator\Report Generator\Form1.cs:Zeile 85.<br />
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br />
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br />
bei System.Threading.ThreadHelper.ThreadStart()
thanks, haape
-- modified at 10:09 Tuesday 16th January, 2007
|
|
|
|
|
How can I Collapse and Expand (CrystalReport) sections programmatically using C#
Regards.
|
|
|
|
|
So i create a webservice...
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
}
and run it...
then i create a pocket pc application.. that should consume this webservice...
add reference to the webservice...
then in the button function i write this:
private void button1_Click(object sender, EventArgs e)
{
localhost.Service x = new localhost.Service();
label1.Text =x.HelloWorld().ToString();
}
then i run this project...wait till it loads...press the button and get the following error
"Unable to connect to the remote server"
i'm waiting for your replies
thank you
|
|
|
|
|
Hi
I am trying to test with windows mobile 5.0 emulator..using C#.Net..
but myHttpWebResponse is always null.httpwebexception coming. Please anybody help me..
This is code:
public static void httpRequest(string uri, bool isGetMethod)
{
try
{
Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create(uri);
if (isGetMethod)
myRequest.Method = "GET";
else
{
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
Stream newStream = myRequest.GetRequestStream();
newStream.Close();
}
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myRequest.GetResponse();
Stream streamResponse = myHttpWebResponse.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
Char[] readBuffer = new Char[256];
int count = streamRead.Read(readBuffer, 0, 256);
string result = "";
while (count > 0)
{
string resultData = new String(readBuffer, 0, count);
result = result + resultData;
count = streamRead.Read(readBuffer, 0, 256);
}
HTTPClass.resultData = result;
streamRead.Close();
streamResponse.Close();
myHttpWebResponse.Close();
}
catch(Exception e)
{
MessageBox.Show(e.Message.ToString());
}
}
Anybody help me..
Thanks
|
|
|
|
|
Hi all, I'm Alessio.
I've got a little problem.
I read my mailbox with a c# component, but sometimes I receive e-mail with attachments and their file names contain "=?UTF-8?" prefix.
An example is "=?utf-8?q?dt.15.01.2007=20ABC.xls?=" where I know that the real file name is "dt.15.01.2007 ABC.xls".
Is there a class to automatic translate these kinds of strings ?
I'm not sure that format always is "=?utf-8?q?.......?=", so a simple replace with "" may doesn't work.
Can you help me ?
Thanx in advance and excuse me for my bad english
Alessio
|
|
|
|
|
I don't know if there is a method for that, but if there is one, I guess it would be somewhere in the System.Net.Mail namespace.
The exact format of that encoding wrapper can be found in one of the RFCs that specify the MIME[^] format.
The format looks quite straight forward, though. Any non-ASCII character is written as =xx where xx is the hexadecimal number for the character code. To decode the string, you can create a byte array with the character codes of the normal characters and the special byte codes, then use Encoding.GetEncoding(theEncoding).GetString(theByteArray) .
---
Year happy = new Year(2007);
|
|
|
|
|
Thanx.
I'm going to check System.Net.Mail.
Anyway, you say that non-ASCII characters are written as =xx.
Ok, but I don't find this format in my string ("=?utf-8?q?dt.15.01.2007=20ABC.xls?=").
I've got "=?" that seems to be like an "open tag" (like '<') and at the end of the string I've got "?=" (like '>').
In the middle of the string I've got a blank space written as "=20" (and this is hex) but is the only non-ASCII character written with the format you say.
Anyway, now I re-check the MIME RFCs.
Thanx again
|
|
|
|
|
Yes, it's hard to say anything about the format from your example file name. There aren't any characters in it that really needs any special encoding. Perhaps the space character is considered a non-standard file name character, that triggers the encoding. The space is of course an ASCII character, but obviously it's decoded anyway.
Anyhow, you should find enough information in the RFCs if you need to decode the format.
---
Year happy = new Year(2007);
|
|
|
|
|
Hello friends,
Could somebody help me to solve the below issue.
I am using odbcdataadapter in my application
the select query for the adapter is something like this..
select * from employees where wages <5000
I display the records in an interface & let the user to edit it.
When the user increases the salary of the employee above 5000.., I call the update function of the adapter class to update the dataset. the databse is updated correctly & the value in the dataset is also updated for the row.
But my prob is, on updating I want the row to be removed from the dataset, since the where condition fails. But it doesn't happen in my case .
Am I missing some important link.. else what is going wrong ..
the where condition works fine only on the initial loading ..
Thanks for the help in Advance
|
|
|
|
|
It sounds like you're not using a DataGridView, otherwise the update would have been made to both the Datasource and the DataGridView.
What are you using to display the records?
Because if you're not using an Autobound Control then you will have to re-execute your Select Query to Fetch the updated records.
Live in fragments no longer. Only connect.
|
|
|
|
|
Don't you think this question would have better chances to be answered, if asked in the VB.NET forum.?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hie guys. I got a problem. Recently i was working on files. All was fine until i tried reading from a binary file such as an mp3, dll file. Reading was not a problem but the problem came when i tried displaying the contents that i read into a byte[]. From the analysis that i did, i realized that the method **Encoding.ASCII.GetString() ** somehow stopped when it encountered a null character i.e binary 0. Can anyone help me? Below is a snippet of the code
.......
.....
FileStream fs=new FileStream(@"C:\example.mp3",FileMode.Open);
byte[] buffer=new byte[ fs.Length ];
fs.read(buffer,0,buffer.Length );
txtOutput.Text=Encoding.ASCII.GetString(buffer);
|
|
|
|
|
Quaspam wrote: From the analysis that i did, i realized that the method **Encoding.ASCII.GetString() ** somehow stopped when it encountered a null character i.e binary 0.
Of course, strings are null terminated. Why would you want to see an MP3 in a textbox ? How do you expect that to be worth anything ? I know the ID3 tags are at the end ( null terminated text for V1 tags, V2 are compressed ), but why show them in a textbox ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Christian Graus wrote: Of course, strings are null terminated
That's why romans were not using strings. They were not not used to 0's (just I, II, III, ...)
SkyWalker
|
|
|
|
|
Can a classlibrary detect an event occurrance in the main form which uses the class library. if so how to detect that?
|
|
|
|
|
If a class exposes an event, and another class subscribes to it, then where those classes come from is irrelevant.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Events are only detected on Windows Forms. So you can pass whatever action you want to your class library from your Form's raised event. Dont worry about the class library being unable to handle events.
Allow the Form to do that.
Live in fragments no longer. Only connect.
|
|
|
|
|
Hi.
This one is realy nasty.
Does anybody know if there is a free .NET library for handleing MIME messages(used for SOAP attachments)?
I'm accessing a java-powered web service and I need to send attachments to it. The standards it supports for receiving atachments from clients are MIME and DIME. However, there are also functions that send files from the service back to me. And here is the problem: THE ONLY FORMAT USED BY THE SERVICE FOR SENDING ATTACHMENTS IS MIME. AND .NET HAS NO SUPPORT FOR MIME. So I get exceptions when getting the response from the server.
Is there any way to work with MIME in .NET??
Thanks.
|
|
|
|
|
hi guys
i have about this
if i click on textbox in any program such as Msn messager or notepad etc. how do i find them by using C#?
thanks
|
|
|
|
|
You want to find the textbox control ? There are windows APIs for that, you can PInvoke them in C#. I think it's WindowFromPoint, or something like that.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Can you give me some sample code? please!
|
|
|
|