Question about string manipulation - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Question about string manipulation

I am writing an Excel Macro and need a little help.

I populate a field with the value of a cell from my spreadsheet.

Serial_Number = Worksheets(1).Cells((i + Caselp), 8).Value

My customer wants me to remove the first 2 characters from the Serial Number.

How do I remove the first 2 characters from my varialbe Serial_Number?

Can you reference each character of a string? In C I can reference the 3rd element of a string by using variable_name[2]. Is there anything similar?


Comments

  • infidelinfidel Posts: 2,900Member
    : I am writing an Excel Macro and need a little help.
    :
    : I populate a field with the value of a cell from my spreadsheet.
    :
    : Serial_Number = Worksheets(1).Cells((i + Caselp), 8).Value
    :
    : My customer wants me to remove the first 2 characters from the Serial Number.
    :
    : How do I remove the first 2 characters from my varialbe Serial_Number?
    :
    : Can you reference each character of a string? In C I can reference the 3rd element of a string by using variable_name[2]. Is there anything similar?

    In VB, strings are not considered arrays. Technically they are arrays where each character is two bytes long, but you can't simply refer to mystring[3]. What you CAN do, which is much easier anyways, is use the Mid() function:

    Const constr = "Hello, world!"
    MsgBox Mid(constr, 2)


Sign In or Register to comment.