VB.net字符串处理有一个space方法, 不知道在C#该怎么写。
如下例:dim str as string=space(1024),C#没有space方法该怎样写?
查询了一下MSDN(strings.space方法)
返回由指定数量的空格组成的字符串。
public static string Space(
    int Number
)

解决方案 »

  1.   


                string s = "a";
                s = s.PadLeft(10, ' ');
      

  2.   

    +1 用PadLeft或者PadRight来填充
      

  3.   

    不明白VB,所以没有听明白楼主的意思,你是想把一个string类型的字符串转换成什么
      

  4.   

    回复四楼,我把代码贴上来一下。谢谢大家了。因为以前是VB写的现在在学习C#
    Public Function Read(ByVal SectionName As String, ByVal KeyName As String) As String
        Dim intRetVal As Int32
            Dim strData As String = Space(1024)    Try
          intRetVal = GetPrivateProfileString(SectionName, KeyName, Nothing, strData, strData.Length, _INIFileName)
          If intRetVal > 0 Then
            Read = strData.Substring(0, intRetVal)
          Else
            Read = ""
          End If
        Catch
          Read = ""
        End Try
      End Function
      

  5.   

    我觉得用构造函数就行了
    String s=new String('  ',1024);