Share this page

# lrt_save_searched_string

Correlating Functions

Searches for an occurrence of string in a buffer and saves a portion of the buffer, relative to the string occurrence, to a parameter.

intlrt_save_searched_string( char *buffer, long buf_size, unsigned int occurrence, char *search_string, int offset, unsigned int string_len, char *parm_name );

buffer | The STRING or CARRAY buffer whose contents you want to save.
buf_size | The buffer size.
occurrence | The occurrence number of the search_string (0-based count). For example, if the string occurs three times, and you want the second occurrence, set occurrence to 1.
search_string | The string to search for in the buffer.
offset | The offset relative to the beginning of the string occurrence where you want to begin saving.
string_len | The number of characters to save.
parm_name | Parameter name to be used in subsequent lrt statements to refer to the saved information. Name is enclosed in double-quotes.

The lrt_save_searched_string function searches for a string in a buffer and saves a portion of the buffer, relative to the string occurrence, to a parameter. It counts the number of times search_string appears in the buffer, from 0 until the specified occurrence . (0-based count). It then adds offset to the start of this string occurrence, and saves string_len characters to a parameter named parm_name.

The search_string cannot contain null characters, but the buffer can contain null characters.

It is preferable to use the lrt_save_parm function to save strings from character arrays. Use lrt_save_searched_string only when you need to save a portion of a character array relative to a string occurrence.

## Return Values

The function returns a negative value on failure. On success it returns the position of the saved string in the buffer relative to the start of the buffer (0-based count). For example, if after adding the offset, the beginning of the saved string is the second character in the buffer, then 1 is returned since there is a difference of 1 between this position and the start of the buffer.

## Parameterization

You cannot use standard parameterization for any arguments in this function.

## Example

In the following example, a Certificate is saved to a parameter for later use. The lrt_save_searched_string function saves 16 bytes from the specified olen buffer, to the parameter cert1. The saved string location in the buffer, is 9 bytes past the first occurrence of the string "SCertRep".

There is usually header information before the "ScertRep" string that can vary in length, depending on the recording environment. The lrt_save_searched_string function is useful in this case, because regardless of the header length, the certificate always begins nine bytes past this string.

Copy code

    /* Request CARRAY buffer 1 */
    lrt_memcpy(data_0, sbuf_1, 41);
    lrt_display_buffer("sbuf_1", data_0, 41, 41);
    data_1 = lrt_tpalloc("CARRAY", "", 8192);
    tpresult_int = lrt_tpcall("GetCertificate",
        data_0,
        41,
        &data_1,
        &olen,
        TPSIGRSTRT);
    /* Reply CARRAY buffer 1 */
    lrt_display_buffer("rbuf_1", data_1, olen, 51);
    lrt_abort_on_error();
    lrt_save_searched_string(data_1, olen, 0, "SCertRep", 9, 16, "cert1");
    ==========================================

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: