none
String question RRS feed

  • Question

  •  

    Read the piece of code below.

    I'm converting a database to a PDF here. The problem is if the information is too long in the column and goes across the page into other column spaces, so I want it to stop after 41 characters. However since I don't know all the methods of strings.

    How do you tell the string its OK to print if the character count is below 41?

    &&&&&&

    How do you tell the string to stop if it hits the 41st character and erase what is left?

    PageAd.Canvas.DrawText(testdataset.Tables(0).Rows(x).Item("Name").ToString.Substring(41, 0), "x=20; y=" & ypos2 & "; size=8", objFont)

    Please help! it is frustrating. 

    Thursday, August 23, 2012 7:56 PM

Answers

  • Use Substring method.  It has tow obtions

    1) Substring(start position)  - Get from position to end of string

    2) Substring(start position, number characters)

    Use the 2nd option and make the start character 1.


    jdweng

    Thursday, August 23, 2012 8:18 PM
  • Hello,

    PageAd.Canvas.DrawText(testdataset.Tables(0).Rows(x).Item("Name").ToString.Substring(41, 0), "x=20; y=" & ypos2 & "; size=8", objFont)

    This is a complex expression. You should extract this:

    Dim obj As Object = testdataset.Tables(0).Rows(x).Item("Name")

    If Typeof obj is System.String then

    Dim str As String = Ctype(obj,String)

    ' OK  debug this up to now

    -------

    ' Now

    str = str.Substring(0,41)

    ' Your Drawtext ....

    I hope this helps

    Ellen


    VB2008 Express, VB2010 Express, VST2008 professional Ellens Codegallerie

    Thursday, August 23, 2012 8:46 PM
  • Hi,

    I think, Substring method os the Best option.


    Regards, http://www.shwetalodha.blogspot.in/

    Friday, August 24, 2012 2:36 AM

All replies

  • Use Substring method.  It has tow obtions

    1) Substring(start position)  - Get from position to end of string

    2) Substring(start position, number characters)

    Use the 2nd option and make the start character 1.


    jdweng

    Thursday, August 23, 2012 8:18 PM
  • Hello,

    PageAd.Canvas.DrawText(testdataset.Tables(0).Rows(x).Item("Name").ToString.Substring(41, 0), "x=20; y=" & ypos2 & "; size=8", objFont)

    This is a complex expression. You should extract this:

    Dim obj As Object = testdataset.Tables(0).Rows(x).Item("Name")

    If Typeof obj is System.String then

    Dim str As String = Ctype(obj,String)

    ' OK  debug this up to now

    -------

    ' Now

    str = str.Substring(0,41)

    ' Your Drawtext ....

    I hope this helps

    Ellen


    VB2008 Express, VB2010 Express, VST2008 professional Ellens Codegallerie

    Thursday, August 23, 2012 8:46 PM
  • Hi,

    I think, Substring method os the Best option.


    Regards, http://www.shwetalodha.blogspot.in/

    Friday, August 24, 2012 2:36 AM