PC Review


Reply
Thread Tools Rate Thread

converting VB to C#

 
 
=?Utf-8?B?aHV6eg==?=
Guest
Posts: n/a
 
      25th Feb 2005
How can i convert this lines of codes into C#? Many thanks

for x=65 to 90
SQLHolder.text=SQLHolder.text & "<a href=""alpha.aspx?alpha=" & chr(x) &
chr(34) & _
" class=""LinkClass"">" & chr(x) & "</a> | "
next
SQLHolder.text=SQLHolder.text & " | <a href=""alpha.aspx"">All Names</a>"
End If

 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      25th Feb 2005
Huzz,

I think I would do it like this. Where you have to check it yourself if it
is complete.
(I have the idea that your VBNet code is as not right, and would use the
same Stringbuilder in the VBNet code by the way)

\\\
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for ( int x=65; x< 91 ; x++)
{
sb.Append(@"<a href=""alpha.aspx?alpha=""");
sb.Append((char) x);
sb.Append ((char) 34);
sb.Append (@"class=""LinkClass"">");
sb.Append ((char) x);
sb.Append ("</a> |");
}
SQLHolder.Text = SQLHolder.Text + sb.ToString()
+ "<a href='alpha.aspx'>All Names</a>";
}
///

I hope this helps?

Cor


 
Reply With Quote
 
MasterGaurav
Guest
Posts: n/a
 
      25th Feb 2005
sb.Append ((char) 34);

change it to:

sb.Append("\r\n");



--
Cheers,
Gaurav Vaish
http://www.mastergaurav.org
http://mastergaurav.blogspot.com
--------------------------------

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      25th Feb 2005
Master Gaurav

char 34 is a double quote not a carriage return & linefeed

Cor


 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      25th Feb 2005
Our Instant C# VB.NET to C# converte produces:

for (x = 65; x <= 90; x++)
{
SQLHolder.Text=SQLHolder.Text + "<a href=\"alpha.aspx?alpha=" + (char)(x)
+ (char)(34) + " class=\"LinkClass\">" + (char)(x) + "</a> | ";

}
SQLHolder.Text=SQLHolder.Text + " | <a href=\"alpha.aspx\">All Names</a>";

Download our Demo Edition to easily obtain C# equivalents for these sort of
small VB.NET code snippets (www.instantcsharp.com).

David Anton
Tangible Software Solutions Inc.
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter


"huzz" wrote:

> How can i convert this lines of codes into C#? Many thanks
>
> for x=65 to 90
> SQLHolder.text=SQLHolder.text & "<a href=""alpha.aspx?alpha=" & chr(x) &
> chr(34) & _
> " class=""LinkClass"">" & chr(x) & "</a> | "
> next
> SQLHolder.text=SQLHolder.text & " | <a href=""alpha.aspx"">All Names</a>"
> End If
>

 
Reply With Quote
 
MasterGaurav
Guest
Posts: n/a
 
      25th Feb 2005
Oops!

I got confused with chr(13)

Then, you'd better be using "\"" or sb.Append('"') [ ' " ' ]
:-)
You can avoid the extra step of type-casting. It's costly you see....

--
Cheers,
Gaurav Vaish
http://www.mastergaurav.org
http://mastergaurav.blogspot.com
--------------------------------

 
Reply With Quote
 
MasterGaurav
Guest
Posts: n/a
 
      25th Feb 2005
> SQLHolder.Text=SQLHolder.Text + "<a href=\"alpha.aspx?alpha=" +
(char)(x)

Avoid
(char) (x)
Prefer using:
Convert.ToChar(x)

This is unicode-safe and optimized for internationlized content. I'd
suggest using Convert class a habbit.


--
Cheers,
Gaurav Vaish
http://www.mastergaurav.org
http://mastergaurav.blogspot.com
--------------------------------

 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      25th Feb 2005
Most of the time, we have chosen the C# equivalent that most closely
replicates the run-time behavior of the original VB.NET code, since
ultimately it's the run-time behavior that is most important to developers
converting code from one language to another. We'll take a look at this again
to see if Convert.ToChar is closer than a char cast.

Regards,
David Anton
Tangible Software Solutions Inc.

"MasterGaurav" wrote:

> > SQLHolder.Text=SQLHolder.Text + "<a href=\"alpha.aspx?alpha=" +

> (char)(x)
>
> Avoid
> (char) (x)
> Prefer using:
> Convert.ToChar(x)
>
> This is unicode-safe and optimized for internationlized content. I'd
> suggest using Convert class a habbit.
>
>
> --
> Cheers,
> Gaurav Vaish
> http://www.mastergaurav.org
> http://mastergaurav.blogspot.com
> --------------------------------
>
>

 
Reply With Quote
 
=?Utf-8?B?aHV6eg==?=
Guest
Posts: n/a
 
      28th Feb 2005
Thanks so much to all of you for your help..

"huzz" wrote:

> How can i convert this lines of codes into C#? Many thanks
>
> for x=65 to 90
> SQLHolder.text=SQLHolder.text & "<a href=""alpha.aspx?alpha=" & chr(x) &
> chr(34) & _
> " class=""LinkClass"">" & chr(x) & "</a> | "
> next
> SQLHolder.text=SQLHolder.text & " | <a href=""alpha.aspx"">All Names</a>"
> End If
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need some help converting this to C++ AA2e72E Microsoft C# .NET 2 5th Feb 2010 08:19 AM
Re: Converting .lib to .dll Neil Cowburn Microsoft Dot NET Compact Framework 11 19th Jun 2008 05:33 PM
Converting :mm:ss to ss Phredd Microsoft Excel Worksheet Functions 8 18th Jun 2008 07:25 PM
Converting a date to a text field w/o converting it to a julian da LynnMinn Microsoft Excel Worksheet Functions 2 6th Mar 2008 03:43 PM
help converting c# to c++? =?Utf-8?B?Sm9lbA==?= Microsoft Dot NET Framework 11 17th Aug 2006 08:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:45 AM.