Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Substring characters in Crystal Report

Status
Not open for further replies.

Tamrak

MIS
Jan 18, 2001
213
US
Good afternoon,

I would like to find a simple formula that will return the result based on the substring character.

Let's say I have a field called, "name" (25 characters long).

I am looking formula similar to this:

If substring({name},2) = "R" then
"Foreign"
Else
"Domestic"

// if the 2nd character of the field "name" is "R" then, return me the value of "Foreign" otherwise, return me the value of "Domestic".

I am trying to use Instr but I might use it the wrong way because it does not work.

Thanks a lot !
 
Hi,
Instr returns the position within the tested string of the search character(s)...So

InStr('Smith','m') = 2

So you coul duse
If InStr({name},'R') = 2 then....



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Good evening,

I have another question regarding substring.

I will use the previous question.

Let say that I would like to find three characters residing anywhere in the field "lastame" (characters - 30 length). Assumtion is, I would like to find the lastname that contents the characters -> THA. It does not matter whether they are in the starting, ending or residing in the middle of the field.

In SQL, I can use the % to find the wildcard. Can you recommend me the formula that I should use in order to obtain the result? Thank you.
 
You can still use the Instr() function i.e.

Code:
If Instr({MyTable.LastName},'THA') <> 0 Then
    'Exists'
Else
    'Not Exists
HTH

Gary Parker
MIS Data Analyst
Manchester, England
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top