Showing posts with label return. Show all posts
Showing posts with label return. Show all posts

Wednesday, March 28, 2012

string.remove and while

I have the following method that should remove html comments. But it's not reacting the way I expect. When the loop breaks and I return the string, I get the correct value - all comments are removed. But the loop will not break using neither the while conditional statement or the internal IndexOf check, therefore stuck in an infinite loop (save for the counter that breaks it).

What am I missing??

public static string RemoveComments(string page) {int i = 0;while (page.IndexOf("<!--") > 0) {int _CommentStart = page.IndexOf("<!--");int _CommentEnds = page.IndexOf("-->");if (_CommentStart > 0) {if (_CommentEnds <= _CommentStart) {break; } page.Remove(_CommentStart, (_CommentEnds - _CommentStart)); }if (page.IndexOf("<!--") < 1) { i = 100; } i++;if (i > 10)break; }return page +" " + i.ToString(); }
I'm not following that logic too well - I don't use c# either - but wouldn't this be a case for regular expressions ?
I'm not a regular expressions expert, but I'm sure there is a way to look for that string and remove it.
Do a search on using regular expressions...

Thank you, very good suggestion. I used the following:

System.Text.RegularExpressions.Regex r =new System.Text.RegularExpressions.Regex(@."\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>");return r.Replace(page,string.Empty);

Monday, March 26, 2012

String/Number manip.

In the following line:
txtWage.Text = "$" & Trim(dataReader.GetValue(9).ToString)

It returns $20.0000 I only want it to return back $20.00 -- every search I've done in string manip. has shown me zilch.

Any suggestions?

txtWage.Text = Format(CDbl(Trim(dataReader.GetValue(9).ToString)), "currency")
I think you can use String.Format also to do the same thing, with the format of {0:c}

strings

Pls help me write a function in c#, to exclude all the dots(.) from a string.
Like the string "123.0000" should return "1230000"
Thanks a ton.Use the Replace function or regular expressions
Thanks...

Thursday, March 22, 2012

Strongly Typed Collections

I'm writing a web service that I want to return a strongly typed collection.
If I inherit System.collections.generic.list(of T) it returns an ArrayOfT.
If I inherit CollectionsBase, it also returns an ArrayOf. I want the root
xml element to just be of the class itself (if that makes any sense). Is
this even possible? What do I need to inherit?
If you want a strong object/collection on the outside world (of a web
service)...then the client needs to know something about some kind of strong
collection.
..
Take a look here:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!158.entry
I have a IZebraCollection......which the service and the host know about.
Its WCF, but WCF can be exposed as a webservice.
..
"Dave T" <DaveT@.discussions.microsoft.com> wrote in message
news:A1A6AA44-6974-4B5C-9C11-795D570F46A7@.microsoft.com...
> I'm writing a web service that I want to return a strongly typed
> collection.
> If I inherit System.collections.generic.list(of T) it returns an ArrayOfT.
> If I inherit CollectionsBase, it also returns an ArrayOf. I want the root
> xml element to just be of the class itself (if that makes any sense). Is
> this even possible? What do I need to inherit?