Click here to Skip to main content
15,900,906 members
Home / Discussions / C#
   

C#

 
Questionwinform add splitcontainer docking problem-panel is covered by toolstrip Pin
akira327-Aug-09 8:54
akira327-Aug-09 8:54 
AnswerRe: winform add splitcontainer docking problem-panel is covered by toolstrip Pin
Alan N7-Aug-09 10:09
Alan N7-Aug-09 10:09 
AnswerRe: winform add splitcontainer docking problem-panel is covered by toolstrip Pin
Henry Minute7-Aug-09 15:38
Henry Minute7-Aug-09 15:38 
Questionhow to Retrieve Metadata in office Document using Index Services. Pin
alisolution7-Aug-09 8:28
alisolution7-Aug-09 8:28 
Questionstripping out http response header using Regex.Replace Pin
Jayapal Chandran7-Aug-09 8:15
Jayapal Chandran7-Aug-09 8:15 
AnswerRe: stripping out http response header using Regex.Replace Pin
Moreno Airoldi8-Aug-09 0:48
Moreno Airoldi8-Aug-09 0:48 
QuestionRe: stripping out http response header using Regex.Replace Pin
Jayapal Chandran9-Aug-09 8:43
Jayapal Chandran9-Aug-09 8:43 
AnswerRe: stripping out http response header using Regex.Replace Pin
Moreno Airoldi9-Aug-09 23:34
Moreno Airoldi9-Aug-09 23:34 
Ok I see. Well, if you want to use regexps, the easiest way I can think of is something like:

C#
string HttpText = "HTTP/1.1 200 OK\r\nDate: Fri, 07 Aug 2009 18:10:29 GMT\r\nServer: Apache
/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimi
ted/1.4 FrontPage/5.0.2.2635 PHP/5.2.8\r\nX-Powered-By: PHP/5.2.8\r\nContent-Length: 140\r\
nConnection: close\r\nContent-Type: text/html\r\n\r\nA Word a Moment\r\nWord : somber\r\n\r
\nPron : sombu(r)\r\n\r\nMeaning :\r\n1. Lacking brightness or colour; dull\r\n\r\nExample 
: (empty)\r\n\r\n";

Regex MyRegex = new Regex("\r\n\r\n");
String[] MyStrings = MyRegex.Split(HttpText, 2);
if (MyStrings.Length != 2)
{
    throw new ApplicationException("Error parsing HTTP response!");
}
			
Console.WriteLine("Header:");
Console.WriteLine("-------");
Console.WriteLine(MyStrings[0]);
Console.WriteLine("Body:");
Console.WriteLine("-------");
Console.WriteLine(MyStrings[1]);
Console.WriteLine("-------");


But it doesn't make much sense to use the Regex object here, since the pattern separating header from body is a fixed string ("\r\n\r\n"), so the same can be done using String.Split(), which is simpler and more performing.

If you want to use Regex.Replace(), like in your example, then you will have to limit the number of matches to replace to one, otherwise ALL matches will be replaced with the empty string! See the docs here[^].

Regarding how to read data from a socket, if you check the docs for objects in System.Net.Sockets, like TcpClient[^], you'll see they expose methods to obtain a NetworkStream[^], which you can use to read data. Smile | :)

2+2=5 for very large amounts of 2
(always loved that one hehe!)

GeneralRe: stripping out http response header using Regex.Replace Pin
Jayapal Chandran10-Aug-09 7:38
Jayapal Chandran10-Aug-09 7:38 
GeneralRe: stripping out http response header using Regex.Replace Pin
Moreno Airoldi10-Aug-09 7:53
Moreno Airoldi10-Aug-09 7:53 
QuestionNeed to parse GUID Pin
JohnQuar17-Aug-09 7:53
JohnQuar17-Aug-09 7:53 
AnswerRe: Need to parse GUID Pin
PIEBALDconsult7-Aug-09 8:04
mvePIEBALDconsult7-Aug-09 8:04 
GeneralRe: Need to parse GUID Pin
JohnQuar17-Aug-09 8:07
JohnQuar17-Aug-09 8:07 
GeneralRe: Need to parse GUID Pin
PIEBALDconsult7-Aug-09 8:11
mvePIEBALDconsult7-Aug-09 8:11 
GeneralRe: Need to parse GUID Pin
JohnQuar17-Aug-09 8:16
JohnQuar17-Aug-09 8:16 
GeneralRe: Need to parse GUID Pin
PIEBALDconsult7-Aug-09 8:28
mvePIEBALDconsult7-Aug-09 8:28 
QuestionLooping through multiple textboxes to retrive data using a variable Pin
msg551217-Aug-09 6:59
msg551217-Aug-09 6:59 
AnswerRe: Looping through multiple textboxes to retrive data using a variable Pin
Muhammad Mazhar7-Aug-09 7:11
Muhammad Mazhar7-Aug-09 7:11 
AnswerRe: Looping through multiple textboxes to retrive data using a variable Pin
Ennis Ray Lynch, Jr.7-Aug-09 7:14
Ennis Ray Lynch, Jr.7-Aug-09 7:14 
AnswerRe: Looping through multiple textboxes to retrive data using a variable Pin
Luc Pattyn7-Aug-09 7:23
sitebuilderLuc Pattyn7-Aug-09 7:23 
QuestionHow can I manage then number of applications instances running at the same time over a network? Pin
_awatts7-Aug-09 6:33
_awatts7-Aug-09 6:33 
AnswerRe: How can I manage then number of applications instances running at the same time over a network? Pin
Ennis Ray Lynch, Jr.7-Aug-09 6:46
Ennis Ray Lynch, Jr.7-Aug-09 6:46 
Questionproblem when to actualize the controls of a form Pin
Harry6667-Aug-09 4:52
Harry6667-Aug-09 4:52 
AnswerRe: problem when to actualize the controls of a form Pin
Henry Minute7-Aug-09 16:02
Henry Minute7-Aug-09 16:02 
GeneralRe: problem when to actualize the controls of a form Pin
Harry6668-Aug-09 0:46
Harry6668-Aug-09 0:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.