Check the first 2 characters of string

  • Thread starter Thread starter axapta
  • Start date Start date
A

axapta

Hi Group,
How can I check that the first 2 characters of a string are the percent (%)
sign?
string name = strSurname

Regards
 
Hi Group,
How can I check that the first 2 characters of a string are the percent (%)
sign?
string name = strSurname

Regards

You can get first two chars of a string with substring method like
below:

Dim foo As String = "foo"
'outputs "fo"
foo = foo.Substring(0, 2)

However, i'm not sure why you're looking for first 2 chars of the
string for determining if describes a percentage.

For example, you can use StartsWith("%") function depending on your
implementation of your application.

Thanks,

Onur
 
Hi Group,
How can I check that the first 2 characters of a string are the percent (%)
sign?
string name = strSurname

Regards

If Mid(mystring, 1, 2) = "%%" Then
'Do whatever
End If
 
Kevinp said:
If Mid(mystring, 1, 2) = "%%" Then
'Do whatever
End If

VB6-style: 'If Left(MyString, 2) = "%%" Then...'. You could also use the
'Like' string comparison operator with an appropriate pattern. However, I
doubt that these solutions are better than 'String.StartsWith'.
 
Back
Top