Space() in VB Strings Class and its Equivalent in C#

 

The Below code Demonstrates the use of the Space() function in the Microsoft.VisualBasic.Strings Class

Dim Test As String  ' Returns a string with 10 spaces.
TestString = Space(10)
' Inserts 10 spaces between two strings.
TestString = "Hello" & Space(10) & "World"

So Using this function maynot be supported in certain cases so here is an equivalent that can be used in c#

string s = “Test”;

s = s.PadLeft(2, ” “); // adds leading 2 space

s=”  Test”;

s = s.PadRight(2, ” “); // Toadd spaces to the Right

s=”Test  “

Is s=””;

It becomes “  “

insert the space in the position you want to .

TestString=”Hello”+S+”World”;

Enjoy Coding.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s