How to Strip Leading Spaces and Underscores from Object

T

TomP

I have a string that captures text from a mainframe and would like to know
how to get rid of the underscores and spaces.

Here's an example of what I have

Dim SMPL as String

SMPL = CurrentScreenObject.GetString (3, 30, 25)


Range ( "A14") = SMPL 'text is put on the spreadsheet


Here's an example of what would show up on the spreadsheet .....

___ TEXT
 
E

eliano

I have a string that captures text from a mainframe and would like to know
how to get rid of the underscores and spaces.  

Here's an example of what I have

Dim SMPL as String

SMPL = CurrentScreenObject.GetString (3, 30, 25)

Range ( "A14") = SMPL 'text is put on the spreadsheet

Here's an example of what would show up on the spreadsheet .....

___ TEXT


Hi Tom.
See:
http://www.tmehta.com/regexp/
Buon Natale
Eliano
 
L

Lars-Åke Aspelin

I have a string that captures text from a mainframe and would like to know
how to get rid of the underscores and spaces.

Here's an example of what I have

Dim SMPL as String

SMPL = CurrentScreenObject.GetString (3, 30, 25)


Range ( "A14") = SMPL 'text is put on the spreadsheet


Here's an example of what would show up on the spreadsheet .....

___ TEXT


Try this used defined function:

Function r_l_s_u(s As String) As String
' removes leading spaces and underscores
Dim x As String
x = s
Do While (Mid(x, 1, 1) = "_" Or Mid(x, 1, 1) = " ")
x = Mid(x, 2)
Loop
r_l_s_u = x
End Function

In cell B14 you put the formula =r_l_s_u(A14)

Hope this helps
 
T

TomP

I'm sorry, but, I'm not real sure how to apply this function. Where would I
put my object string SMPL that needs to be trimmed? My next question is how
does cell B14 get in to the picture? Couldn't I just assign the object from
the code?

Thank you,

Tom

Function r_l_s_u(s As String) As String
' removes leading spaces and underscores
Dim x As String
x = s
Do While (Mid(x, 1, 1) = "_" Or Mid(x, 1, 1) = " ")
x = Mid(x, 2)
Loop
r_l_s_u = x
End Function

In cell B14 you put the formula =r_l_s_u(A14)
 
L

Lars-Åke Aspelin

Put this in your code before you store the string in cell A14:

SMPL = r_l_s_u(SMPL)

Hope this helps / Lars-Åke
 
T

TomP

It works now, but what would I have to do to remove 3 more spaces before it
finds the first character? Most of the spaces and underscores were removed.

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top