String Help please

Hi every body

I have a field with a number information, this is a Text.

Some documents has this format type: ###-###-#### and the others document has just #########

I need to validate between 2 database if the phone number exist in both.

I am tring use STRCONV, STRCOMPARE, LIKE etc… but I am not sure, how can i do when 1 string will be less than 2 string? for exm.

result= Strcompare(tphone1,sDoc.Phone(0), 2)

(i am not sure about this formula)

SO if result = -1 (String1 is < String2)

and then how can delete or avoid the char. [-] into the String2 (416-525-2726)???

Thank you so much

Claudia

Subject: String Help please.

Check the help for the Replace function. You’ll need to construct some arrays to hold the data, but you can use it to replace any hyphens in the phone numbers with null strings and then compare the results.

Subject: RE: String Help please.

Oh duh, that would be a much cleaner and more versatile way to do it. Replace is definitely the way to go here.

Subject: String Help please.

I’m not certain I follow you entirely, but I will address the question you ask at the end since it seems that that is the main thrust of your question. :slight_smile:

so let’s say you have a variable named String2 with a value of “416-525-2726” and you want to get rid of the hyphens. I’m assuming you know that if there are hyphens at all that there are two of them since you’re storing phone numbers. So all you need to do is pass the phone numbers through the following function before comparing them:

Function TelCompare(strTelNum As String) As String

Dim varSplitTel As Variant



varSplitTel = Split(strTelNum, "-")

If Ubound(varSplitTel) < 1 Then

	TelCompare = varSplitTel(0)

Else

	TelCompare = varSplitTel(0) & varSplitTel(1) & varSplitTel(2)

End If

End Function

The function will return 4165252726 whether it was passed 416-525-2726 or 4165252726.

Subject: RE: String Help please.

Hi Jeremiah

Maybe you have the point, but I realize that this database is in version R5, so i couldn’t find some thing about “split”, maybe this funtion is workin on R6

Thank you…

Subject: String Help please.

First, here is a function that I found on this forum:==============================================

Function ReplaceSubString(SourceS As String, SearchS As String, ReplaceS As String) As String

While Instr(SourceS, SearchS) > 0

SourceS = Left$(SourceS, Instr(SourceS, SearchS) - 1) + ReplaceS + Right$(SourceS, LenSourceS) - Instr(SourceS, SearchS) - LenSearchS) + 1)

Wend

ReplaceSubstring = SourceS

End Function

==============================================

…add that function to your form or somewhere where you can access it when you want to compare the strings.

Then you can use this function to get rid of any “-” characters, as well as any “(” and “)” and then trim it.

That will leave you with pure numbers in the strings, and you can simply compare the two.

Here is an example:

dim str1 as string, str2 as string

str1 = … 'here you set the first string

str2 = … 'here you set the other string

str1 = trim(ReplaceSubString(str1,“-”,“”))

str2 = trim(ReplaceSubString(str2,“-”,“”))

if str1 = str2 then

msgbox “Strings are the same”

else

msgbox “Strings are different”

end if

Subject: RE: String Help please.

Hi Matt

This solution sound good, but I couldn’t fix up the line:

SourceS = Left$(SourceS, Instr(SourceS, SearchS) - 1) + ReplaceS + Right$(SourceS, LenSourceS) - Instr(SourceS, SearchS) - LenSearchS) + 1)

made me conflicts with i tried to run my script

thank you.