LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

inserting a new sting in an existing string at a particular location in the existing string

Is there a way of inserting a new sting in an existing string ? It is is kind of a search and replace fuction.
thanks,
Jsugrim
0 Kudos
Message 1 of 4
(3,447 Views)
Jsugrim-

I don't think there's a simple, single function provided anywhere in the standard C library or in an NI library that does this - you might have to build this up from more primitive functions.

You can use the regular expression front panel  found in the toolslib\toolbox folder of your CVI installation to do effective string searches and find the substring, then create a temp string using the replacement substring, then copy the temp string into the original.  There are several functions available for copying strings around, strcpy, strncpy, etc.  The strstr function will find a substring for you too (but won't do a replacement).

Menchar

Message 2 of 4
(3,444 Views)

I can find the position in the string I want to to do the replacement operatation? how do i do the insertion at that point.

Here is a portion of my code

 StartofSearchString = FindPattern (buffer, 0, bytesread, "CoilBaudRate", 1, 1);
    StopofSearchString = FindPattern (buffer, StartofSearchString , 25, "\n", 1, 1);
    value= StopofSearchString-(StartofSearchString + (StringLength("CoilBaudRate")+ 1));
    i =  sprintf (temp,"%i", CoilBaudRate);
    FillBytes (buffer, (StartofSearchString+(StringLength("CoilBaudRate"))+1), i,CoilBaudRate );

is there a function like the fillbyte that do the insertion

thanks,

jsugrim

0 Kudos
Message 3 of 4
(3,442 Views)
You can do a strcpy or any string movement command, just provide a destination address inside the string.    Since strings are arrays of chars, a substring location is just an offset into the char array.

Menchar

Message 4 of 4
(3,439 Views)