|
-
Jul 27th, 2003, 08:56 AM
#1
Thread Starter
Sleep mode
[3] again , VB.NET equivalent ?[Resolved]
What's the replacement of Space function (VB6 Function) in .NET . It's used to return a string consisting of the specified number of spaces.
VB Code:
Private Const MAX_PATH As Short = 260
Dim sBuffer As String
sBuffer = [B]Space[/B](MAX_PATH * 2)
Last edited by Pirate; Jul 28th, 2003 at 11:52 AM.
-
Jul 27th, 2003, 11:59 AM
#2
Addicted Member
Uhm... Space. 
VB Code:
Dim str As String
str = Space(500)
-
Jul 27th, 2003, 04:44 PM
#3
Thread Starter
Sleep mode
No , that's imported from VisualBasic namespace . Did you actually read my post ??? . I said I don't want to continue using Space function , otherwise I want something similar to it by string or whatever obj . Pure .NET way .
-
Jul 27th, 2003, 04:54 PM
#4
try this
VB Code:
Imports System.Text
'/// as usual at the top.
'///////////////////////////
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strString As New StringBuilder(256)
strString.Append("A", strString.Capacity)
MessageBox.Show(strString.ToString)
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jul 27th, 2003, 05:01 PM
#5
here's a better example , using an api call but , showing how the stringbuilder works inplace of the Space thing from vb6 :
VB Code:
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As IntPtr, ByVal lpClassName As StringBuilder, ByVal nMaxCount As Integer) As Integer
'/// i modified it to StringBuilder ^^^
'///////////////////////////////////////////////
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strString As New StringBuilder(256)
GetClassName(Me.Handle, strString, strString.Capacity)
MessageBox.Show(strString.ToString)
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jul 27th, 2003, 05:13 PM
#6
Thread Starter
Sleep mode
Can't this be done with string class , because I'm getting a lot of errors in the subsequent code . They're all based on string objs .
Thanks .
-
Jul 27th, 2003, 05:31 PM
#7
you can make a string have a capacity by doing something like this .....
VB Code:
<VBFixedString(256)> Public strString As String
but it'd have to be in a public area.
however the correct .NET method is StringBuilder and it's far faster than String.
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jul 27th, 2003, 05:50 PM
#8
Thread Starter
Sleep mode
I converted stringbuilder to string but this won't be converted ! How the heck can I modify this to return string ??
VB Code:
sBuffer = CType(sBuffer.ToString.Substring(0, lNullPos - 1), String)
-
Jul 27th, 2003, 05:53 PM
#9
Thread Starter
Sleep mode
ToString , CType , DirectCast won't work either . . Seems I'm stuck there no other options left ?
-
Jul 27th, 2003, 06:22 PM
#10
Frenzied Member
Pirate it seems to me that you are using a conversion program. Anyway try this.
Code:
sBuffer = (string)sBuffer.ToString.Substring(0, lNullPos - 1);
-
Jul 27th, 2003, 06:26 PM
#11
Thread Starter
Sleep mode
error :
'String' is a class type, and so is not a valid expression.
No I'm not using any program . But why you said that ?
-
Jul 27th, 2003, 06:28 PM
#12
Thread Starter
Sleep mode
We're here talking about VB.NET code .
-
Jul 27th, 2003, 06:32 PM
#13
Frenzied Member
Nevermind what I said. I thought you wanted it converted to C#.
-
Jul 28th, 2003, 11:12 AM
#14
Addicted Member
Sorry 'bout my first response, Pirate. Try this:
VB Code:
Dim str As New String(" ", 25)
That will initialize a string object with 25 spaces.
-
Jul 28th, 2003, 11:44 AM
#15
Thread Starter
Sleep mode
It doesn't work .
-
Jul 28th, 2003, 11:49 AM
#16
Thread Starter
Sleep mode
This works 
VB Code:
Dim str As New String(" ", 260)
Thanks Sheppe
-
Jul 28th, 2003, 11:54 AM
#17
You can also use padleft and padright if you need to add spaces or any character to an existing string.
VB Code:
Const MAX_PATH As Short = 260
Dim str As String = "Something" 'or String.empty
str = str.PadLeft(MAX_PATH * 2, " ")
MsgBox("'" & str & "'")
-
Jul 28th, 2003, 11:59 AM
#18
Thread Starter
Sleep mode
I don't want to add spaces , I wanted to get a string consisting of the specified number of spaces (260 chars) .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|