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


VB string function equivalent in c#...

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

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

Expert Comment

ID: 23669439
Like this:

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

Expert Comment

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)

Author Comment

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#.
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

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:


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.

Author Closing Comment

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

Expert Comment

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

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