Can save memory by setting the length of the variables. But you have to keep in mind that you cannot assign a longer variable to a shorter one. The system will not give you an error but the program will not work properly. You have to assign it using "LeftStr" to adapt the lengths.
'***********************************************************************
'Funciones String
'Pic18F26k22, OshonSoft Pic18 Basic Compiler v5.32
'***********************************************************************
#define STRING_MAX_LENGTH = 75
UART1_Init 115200
main:
Dim String0 As String 'Maximum length established with the directive.
Dim String1[6] As String 'Length set by user.
Dim String2[6] As String
Dim String3[6] As String
String0 = "$GNRMC,000000.00,A,3723.02837,N,00150.39853,W,0.820,188.36,110706,,,A*74"
'Copy of a higher variable to a lower variable must be limited to the length of the lower variable.
String1 = LeftStr(String0, 6)
String2 = "GNRMC"
If match(String1, 1, String2) = 1 Then
UART_Write "Ok", CrLf
Else
UART_Write "No match", CrLf
Endif
End
'The corresponding match function (IDE Pic18 v5.32).
Function match(input_str[6] As String, str_ix As Byte, match_str[5] As String) As Byte 'variable names can be changes
Dim position_counter As Byte
Dim shortposition As Byte
position_counter = str_ix
shortposition = 0
While match_str(shortposition) > 0
If input_str(position_counter) = match_str(shortposition) Then
ReturnValue 1 'set the match indicator to valid
shortposition++ 'increment the short string position counter
Else
ReturnValue 0 'set the match indicator To Not valid
Exit 'jump out of the function
Endif
position_counter++
Wend
End Function 'the corresponding match function