LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

String Function Questions

So i know there's probably a million different ways to do this and I don't remember any of them.  How do I do the following:
 
Message1 = "Why can't I remember anything from C"
Message2 = "from C"
 
How do I extract the last character (or any number of characters) from Message 1 and then compare it to see if it's equal to message 2?Robot Indifferent
0 Kudos
Message 1 of 3
(3,170 Views)

Using ANSI C something like the following should do the trick ( remember: last character of a string  is string[strlen(string )-1])

success = 1;

for (i = 0, (i <strlen(Message2)) && success; i--)

    success = Message2[strlen(Message2) -1-i] == Message1[strlen(Message1) -1-i]

If you prefer to use the NIs libraries you could use CompareStrings with an offset.

CompareStrings( Message1,StringLength (Message1)-StringLength (Message2),Message2,0,1) == 0;

 

0 Kudos
Message 2 of 3
(3,163 Views)

try the simple CVI function:

FindPattern() in Formatting and IO library /string manipulation:

found_at_pos = FindPattern (buffer_to_seach, start_index, num_of_bytes,        "pattern_to_find", case_sensitive, start_at_end);

 

layosh

0 Kudos
Message 3 of 3
(3,127 Views)