webclient vs httpwebrequest

  • Thread starter Thread starter mp
  • Start date Start date
M

mp

wondering if i need to move to httpwebrequest
i'm getting this string back
the first "name" has a comma in it,
so my parsing via split on comma doesn't work right
"Vmware, Inc. Comm",90.08,89.31,"+1.51%",-
"Holly Corporation",41.94,41.48,"+1.13%",-
"Alliance Fiber Op",17.12,16.91,"-0.89%",-
"Rockwell Automati",76.05,75.60,"-1.56%",-

i'm going to research that now, but if anyone has
initial pointers, i'm all ears
:-)
thanks
mark
 
mp said:
wondering if i need to move to httpwebrequest
i'm getting this string back
the first "name" has a comma in it,
so my parsing via split on comma doesn't work right
"Vmware, Inc. Comm",90.08,89.31,"+1.51%",-
"Holly Corporation",41.94,41.48,"+1.13%",-
"Alliance Fiber Op",17.12,16.91,"-0.89%",-
"Rockwell Automati",76.05,75.60,"-1.56%",-

i'm going to research that now, but if anyone has
initial pointers, i'm all ears
:-)
thanks
mark

http://www.codeproject.com/KB/database/CsvReader.aspx
http://commonlibrarynet.codeplex.com/
http://www.switchonthecode.com/tutorials/csharp-tutorial-using-the-built-in-oledb-csv-parser

Isn't Google wonderful?
 
Jason Keats said:

indeed it is, once you know what you're lookinng for <g>

the first one in your list is over my head
there are four or five folders-i don't know if i need to add all that to my
little project
when i just try running the top level .sln file i get an error saying
CsvReaderDemoWeb is not supported by my version of c#(2008 express)
so not sure what's the cause of that. when the project opens there are 358
errors.
it would take me too long to figure all that out, so i look at the second
one

that site mentions
A collection of very reusable code and components in C# 4.0 ranging from
ActiveRecord, Csv, Command Line Parsing, Configuration, Validation, Logging,
Collections, Authentication, and much more.
it also says an older version works on 3.5 which is what i'm on,
but i don't know what i need to download from that site
it appears to be an entire library or framework..don't know if that's
overkill to just parse a simple csv string

the last one shows an http method
on the surface seems simpler for me to figure out

one question...all solutions are designed to read a csv file (naturally)
in my case i have a csv string not a file
is it worth saving to a temp file so as to read the file with one of these
methods?
or is there a way that i'm not seeing to pass it the string and avoid
the redundant file io?

i'm also searching google to see if i can find one simple enough for me to
understand how to use

thanks mark
 
one question...all solutions are designed to read a csv file (naturally)
in my case i have a csv string not a file
is it worth saving to a temp file so as to read the file with one of these
methods?
or is there a way that i'm not seeing to pass it the string and avoid
the redundant file io?

StringReader or MemoryStream should avoid disk IO.

Arne
 
Jason Keats said:
mp wrote: []>
Isn't Google wonderful?

also found this
http://www.codeproject.com/KB/recipes/Basic_CSV_Parser_Function.aspx
but it uses ArrayList
isn't that a deprecated object? thought i'd seen people saying not to
use???
i'll try replacing with List and see if it still works
just wondering anyone's opinions

It should work.

There are no reason to believe being more type safe
should break the code.

Arne

PS: The code looks very engineered compared to the modest
complexity of the problem, but ....
 
Arne Vajhøj said:
Jason Keats said:
mp wrote: []>
Isn't Google wonderful?

also found this
http://www.codeproject.com/KB/recipes/Basic_CSV_Parser_Function.aspx
but it uses ArrayList
isn't that a deprecated object? thought i'd seen people saying not to
use???
i'll try replacing with List and see if it still works
just wondering anyone's opinions

It should work.

There are no reason to believe being more type safe
should break the code.

Arne

PS: The code looks very engineered compared to the modest
complexity of the problem, but ....

right, i'm still looking on google, several hundred links later
still looking for a simple single class i can drop in my code and use.
I appreciate Jason's links but due to my inexperience i dont' know if i can
take one class out of 4 or 5 folders of code and use it. and I'm not sure
if my attempt to run the sln file failure is possibly it is 4.0 and i
haven't
been brave enough to install 2010 yet?
:-)
 
Arne Vajhøj said:
Jason Keats said:
mp wrote: []>
Isn't Google wonderful?

also found this
http://www.codeproject.com/KB/recipes/Basic_CSV_Parser_Function.aspx
but it uses ArrayList
isn't that a deprecated object? thought i'd seen people saying not to
use???
i'll try replacing with List and see if it still works
just wondering anyone's opinions

It should work.

There are no reason to believe being more type safe
should break the code.

Arne

PS: The code looks very engineered compared to the modest
complexity of the problem, but ....

yes List<string> "worked" ie compiled
still working on figuring out how to get it into datatable

the description of the code was something about a statemachine technique
to deal with quotes, single and double, and commas in quotes iirc
 
Arne Vajhøj said:
mp wrote:
[]>
Isn't Google wonderful?

also found this
http://www.codeproject.com/KB/recipes/Basic_CSV_Parser_Function.aspx
but it uses ArrayList
isn't that a deprecated object? thought i'd seen people saying not to
use???
i'll try replacing with List and see if it still works
just wondering anyone's opinions

It should work.

There are no reason to believe being more type safe
should break the code. ....
PS: The code looks very engineered compared to the modest
complexity of the problem, but ....

right, i'm still looking on google, several hundred links later
still looking for a simple single class i can drop in my code and use.
I appreciate Jason's links but due to my inexperience i dont' know if i can
take one class out of 4 or 5 folders of code and use it.

Then go for something simpler.

Here are something that I had on the shelf:

public static List<string> Parse(String s, char delim, char quote)
{
List<string> res = new List<string>();
StringBuilder sb = new StringBuilder();
bool inquote = false;
int ix = 0;
while(ix < s.Length)
{
if(s[ix] == delim)
{
if(inquote)
{
sb.Append(s[ix]);
}
else
{
res.Add(sb.ToString());
sb = new StringBuilder();
}
}
else if(s[ix] == quote)
{
if(ix + 1 < s.Length && s[ix+1] == quote)
{
sb.Append(s[ix]);
ix++;
}
else
{
inquote = !inquote;
}
}
else
{
sb.Append(s[ix]);
}
ix++;
}
res.Add(sb.ToString());
return res;
}

It is not perfect, but it is a single method that you
can call with a single line.

Arne
 
Arne Vajhøj said:
mp wrote:
[]>
Isn't Google wonderful?

also found this
http://www.codeproject.com/KB/recipes/Basic_CSV_Parser_Function.aspx
but it uses ArrayList
isn't that a deprecated object? thought i'd seen people saying not to
use???
i'll try replacing with List and see if it still works
just wondering anyone's opinions

It should work.

There are no reason to believe being more type safe
should break the code.
PS: The code looks very engineered compared to the modest
complexity of the problem, but ....

yes List<string> "worked" ie compiled
still working on figuring out how to get it into datatable

You need to store the elements from the list in
columns in a row.
the description of the code was something about a statemachine technique
to deal with quotes, single and double, and commas in quotes iirc

Yes. That is the implementation.

If you need to fiddle with that, then you need to
understand the state machine.

If you just need to use it, then just use it and don't
care about how it works.

Arne
 
Arne Vajhøj said:
Arne Vajhøj said:
On 23-01-2011 13:21, mp wrote:
mp wrote:
[]>
Isn't Google wonderful?
[]

yes List<string> "worked" ie compiled
still working on figuring out how to get it into datatable

You need to store the elements from the list in
columns in a row.

right, it was just that at first i tried sending my whole string to the
funciton
which of course lost my linebreaks
then i realized i split on newline first
then send each line to the function for the comma "split/parse"
 
Arne Vajhøj said:
On 23-01-2011 13:21, mp wrote:
mp wrote:
[]>
Isn't Google wonderful?
[]

yes List<string> "worked" ie compiled
still working on figuring out how to get it into datatable

You need to store the elements from the list in
columns in a row.

right, it was just that at first i tried sending my whole string to the
funciton
which of course lost my linebreaks
then i realized i split on newline first
then send each line to the function for the comma "split/parse"

Or wrap the string in a StringReader and use ReadLine
to read the individual lines.

Arne
 
Arne Vajhøj said:
On 23-01-2011 16:49, mp wrote:
On 23-01-2011 13:21, mp wrote:
mp wrote:
[]>
Isn't Google wonderful?
[]

yes List<string> "worked" ie compiled
still working on figuring out how to get it into datatable

You need to store the elements from the list in
columns in a row.

right, it was just that at first i tried sending my whole string to the
funciton
which of course lost my linebreaks
then i realized i split on newline first
then send each line to the function for the comma "split/parse"

Or wrap the string in a StringReader and use ReadLine
to read the individual lines.

Or to get back to the original question.

If you switch to HttpWebRequest, then you can get
a StreamReader and process the lines as they are read.

For a really huge file that would be the best.

Arne
 
Arne Vajhøj said:
Arne Vajhøj said:
On 23-01-2011 13:21, mp wrote:
mp wrote:
[]>
Isn't Google wonderful?
[]

Then go for something simpler.

Here are something that I had on the shelf:

public static List<string> Parse(String s, char delim, char quote)
{
[]
}

It is not perfect, but it is a single method that you
can call with a single line.

Arne

Thanks for that Arne
i'll try it also
 
Back
Top