Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VB string function equivalent in c#...

Posted on 2009-02-18
6
Medium Priority
?
1,097 Views
Last Modified: 2012-06-27
How do i convert this vb code into c#

strTemp = String(255, Chr$(0))
0
Comment
Question by:ube100
  • 4
  • 2
6 Comments
 
LVL 39

Expert Comment

by:abel
ID: 23669439
Like this:

string strTemp = new string('\0', 255);
0
 
LVL 39

Expert Comment

by:abel
ID: 23669463
The '\0' part is the equivalent of the the Chr(0) function (ascii character NUL).

Btw, I assume you meant this as VB code, because the mentioned VB code will not compile (first parameter of constructor cannot be an Integer):

Dim strTemp As New String(Chr(0), 255)
0
 

Author Comment

by:ube100
ID: 23669642
next code is:

lRet = GetTempPath(255, strTemp)

API function for the GetTempPath is declared like this:

Private Declare Function GetTempPath Lib "Kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

How will I convert this into C#.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 39

Accepted Solution

by:
abel earned 1000 total points
ID: 23669673
You don't need API functions old style anymore in .NET. You can use the .NET library functions, which are type safe. In this case:

System.IO.Path.GetTempPath()

If you do not want the "System.IO" in front of it, you can put that in the using headers:

using System.IO;

...
string strTemp = Path.GetTempPath();

As you can see, you do not need to initialize your variables with nullpadded strings anymore. Quite handy this way, isn't it? And whether you use VB.NET or C#.NET or any other .NET language, you can always use these base libraries.
0
 

Author Closing Comment

by:ube100
ID: 31548211
thank very much sir for help!!!
0
 
LVL 39

Expert Comment

by:abel
ID: 23669984
You're welcome, glad it helped :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question