locked
How to take spaces in a string using SubString RRS feed

  • Question

  • User179837873 posted

    Hi,


    Dim strValue as String=""

    Dim strOutputValue as String=""

    strValue ="One"

    strOutputValue  = "One+(7 Spaces here) "

    strValue is changing dynamically that is fixed 10 characters.

    but i need Out is

    MsgBox("Total characters  " &strOutputValue.Length)

    10


    Monday, January 18, 2010 10:46 AM

Answers

All replies

  • User-1226263862 posted

    So you want to add spaces, up to 10, depending on the length of strValue?  For instance:

    Dim strValue As String = Nothing
    Dim strOutputValue = Nothing
    strValue = "Three"
    strOutputValue = strValue + _ _ _ _ _

    Or if strValue = "Two" then
    strOutputValue = strValue + _ _ _ _ _ _ _

    So based on the length of strValue you can calculate how many spaces to add.  Is this for display purposes only?  Or are you wanting to store the values in the database as well?

    Monday, January 18, 2010 8:14 PM
  • User1006193418 posted

    Hi,

    You need to use String.PadRight method: http://msdn.microsoft.com/en-us/library/34d75d7s.aspx.

            Dim strValue As String = ""
            Dim strOutputValue As String = ""
            strValue = "One"
            strOutputValue = strValue.PadRight(10)

    Oh, you may also be interested in the String Constructor (Char, Int32): http://msdn.microsoft.com/en-us/library/xsa4321w.aspx.

            Dim strValue As String = ""
            Dim strOutputValue As String = ""
            strValue = "One"
            strOutputValue = strValue & New String(" "c, 7)

    Best Regards,
    Shengqing Yang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 22, 2010 4:22 AM
  • User1364706731 posted

    Refer this link

    http://dotnetperls.com/substring-vbnet

    Tuesday, February 9, 2010 12:49 AM