How can I find small letters

P

Pawel

Suppose I would like to find any instance of small letter
(any small letter) in my document together with paraghraph
marks just after it (strings like: "a" + chr$(13), "b" +
chr$(13), ...).

I know I could do that in that way:

If (strText = ("a" + Chr$(13))) or (strText = ("b" +
chr$(13))) or ... Then

Is there a simpler way?

Thank you.
 
M

Mark Tangard

Hi Pawel,

You could use the 'Like' operator and then check the
ASCII value of the first character of the string.
So since Asc(a) = 97 and Asc(z) = 122, you could use:

If strText Like "?" & vbCr And _
Asc(Left(s, 1)) >= 97 And _
Asc(Left(s, 1)) <= 122 Then ...

But if you needed to do this several times within a
procedure the logical thing would be to write it up
as a *function*:

Function SmallLetterThenPara(x as String) as Boolean
If x Like "?" & vbCr And _
Asc(Left(s, 1)) >= 97 And _
Asc(Left(s, 1)) <= 122 Then
SmallLetterThenPara = True
End Function

Then you could test a string elsewhere in the module by
coding simply:

If SmallLetterThenPara(strText) = True Then....
 
K

Klaus Linke

Hi,

If (strText Like "[a-z]" & vbCr) then ...
should work, too.

If you want to find the text in the document, and not in a string, you
could do a wildcard search (check "Match wildcards", Find what: [a-z]^13).
The macro recorder should give you some usable code.

Regards,
Klaus
 

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