String

MultiByteToWideChar, sprintf, sprintf_l, strcat, strchr, strcmp, strcmpi, strcpy, StrExchangeChar, stristr, strlen, strlwr, strrchr, strstr, strupr, WideCharToMultiByte

MultiByteToWideChar

Description 

 MultiByteToWideChar(
   char  wchar_str,
   char  char8_str
);

This function maps a character string to a wide character string.

Parameters

char wchar_str

Pointer to a buffer that receives the converted string.

char char8_str

Pointer to the character string to convert.

See Also 
WideCharToMultiByte

StrExchangeChar

Description 

 StrExchangeChar(
   char *Int_str1,
   int  Int_Char1,
   int  Int_Char2
);

This function replaces all occurrences of a character within the specified string.

Parameters

char *Int_str1

A sequence of characters.

int Int_Char1

ASCII number of the replacement character (insert this character instead).

int Int_Char2

ASCII number of the character to be replaced (search for this character).

//When running an external program, quotation marks cannot be used inside a variable,
//we will use a dollar sign instead.
char txt[1000];
char ImageJ[260] = "$C:\Fiji.app\ImageJ-win32.exe$"; 
char ImageJmacro[260] = "$nis.ijm$";
strcat(txt, ImageJ);
strcat(txt, " -batch ");
strcat(txt, ImageJmacro);
StrExchangeChar(txt, 34, 36); //Exchange dollars for qotation marks - ASCII codes: 36 = [$], 34 = ["]
WaitText(0, txt);
Int_ExecProgramWait(txt);  //Call the program and wait for it to finish
WaitText(0, "DONE");   
WideCharToMultiByte

Description 

 WideCharToMultiByte(
   char  char8_str,
   char  wchar_str
);

This function maps a wide character string to a new character string.

Parameters

char char8_str

Pointer to a buffer that receives the converted string.

char wchar_str

Pointer to the wide character string to convert.

See Also 
MultiByteToWideChar

sprintf

Description 

 sprintf(
   char *Int_Buffer,
   char *Int_Format,
   char *Int_Arguments
);

This function formats and stores a series of characters and values in the string variable buffer. Each argument in Int_Arguments (if any) is converted and output according to the corresponding format specification in formatSpec.

Parameters

char *Int_Buffer

String variable to which formatted output should be copied.

char *Int_Format

A format specification which consists of optional and required fields.

char *Int_Arguments

Specifies zero or more optional arguments in a string, separated by commas. The number and type of the optional arguments depend on the corresponding format-control character sequences specified in the formatSpec parameter. When arguments is an empty string, formatSpec will be copied to buffer, including legal format specifications.

Return Values

This function returns the characters written to buffer.

// sprintf example - shows how a character, tab, CR  and float numbers are converted to output string.
char output[80],filename[80],title[80];
// the correct format specifier should look like this: 
sprintf(buf,"Z position = %.3f","zpos");
// %.3f - means floating point value formated with precision to three digits after the decimal point. 
// Trailing zeros are truncated. The precision is variable, you can change it.
// Use %-.3f to keep trailing zeros in place, which results in something like this: "Z position = 12.400"
Get_Filename(FILE_IMAGE,filename);
Get_FileTitle(title,filename);
sprintf(output,"API Example - sprintf function. Last opened image: %s","title");
Int_CreateTextWindow(output,0,RGB(0,0,128),RGB_WHITE,100);
Wait(2);
sprintf(output, "Uppercase 'A' : %c\nTab:\t\t\t Third Tab \n CR:\n\nProgram: %s A\nquarter: %-07.3f ","65, `NIS-Elements`, 1/4");
Int_CreateWindow(WND_1,"sprintf example",0, 0, 0, 450, 560,"Header:\n\n",1,1,0.00000,1,1,1,"Arial,B,8");
Int_SetWindowText(WND_1, output, TRUE);    
Int_CloseTextWindow();

Note

%[flags] [width] [.precision] type - Only % and type are obligatory. Any text in formatSpec which does not belong to a legal format specification will simply be copied to buffer. Each field of the format specification is a single character or a number signifying a particular format option. The simplest format specification contains only the percent sign and a type character (for example, %s). The optional fields, which appear before the type character, control other aspects of the formatting. The fields in a format specification are described as follows: Optional character or characters that control justification of output, blanks, leading zeros and hexadecimal prefix. More than one flag can appear in a format specification. - (minus)Pad the output value with blanks or zeros to the right to fill the field width, aligning the output value to the left. If this field is omitted, the output value is padded to the left, aligning it to the right. With floating point numbers, trailing zeros up to precision are generated. Note that right alignment of numbers or text is only handled correctly when using a proportional font. 0 (zero) Pad the output value with zeros to fill the field width. If this field is omitted, the output value is padded with blank spaces. With floating point numbers, leading zeros up to width are generated. Required character that determines whether the associated argument is interpreted as the ASCII-code for a character (c), a literal string enclosed in backquotes or a string variable (s), an integer or -variable (d or i), a floating point number or -variable (f ) or a hexadecimal number or -variable (x). Floating point numbers will be represented in exponential format if the exponent is -4 or lower and there will be no loss of accuracy, or if the exponent is 15 or higher. Integer- and hexadecimal values which absolute value exceeds 2,147,483,647 are truncated.

See Also 
atof, strcat, strcmp, strcmpi, strcpy, strlen, strlwr, strrchr, strupr, memcmp, memcpy, memset

sprintf_l

Description 

 sprintf_l(
   char *Int_Buffer,
   char *Int_Format,
   char *Int_Arguments
);

This function equals the sprintf function but is region-dependent. If a number is included in the string, the decimal symbol ("," or ".") will be corrected according to the regional and language settings of your operating system.

Parameters

char *Int_Buffer

String variable to which formatted output should be copied.

char *Int_Format

A format specification which consists of optional and required fields.

char *Int_Arguments

Specifies zero or more optional arguments in a string, separated by commas. The number and type of the optional arguments depend on the corresponding format-control character sequences specified in the formatSpec parameter. When arguments is an empty string, formatSpec will be copied to buffer, including legal format specifications.

See Also 
sprintf

strcat

Description 

 strcat(
   char *str1,
   char *str2
);

This function appends str2 to str1, terminates the resulting string with a null character, and returns a pointer to the concatenated string str1. This function operates on null-terminated strings. The string arguments to these functions are expected to contain a null-byte, marking the end of the string. No overflow checking is performed when strings are copied or appended.

Parameters

char *str1

Pointer to str1

char *str2

Pointer to str2.

See Also 
atof, sprintf, strcmp, strcmpi, strcpy, strlen, strlwr, strrchr, strupr, memcmp, memcpy, memset

strchr

Description 

 strchr(
   char *str,
   int  value
);

This function returns a pointer to the first occurrence of value (converted to char) in str1. The converted character value may be the null character ; the terminating null character of str1 is included in the search. The function returns NULL if value is not found. strchr operates on null-terminated strings. The string arguments to this functions is expected to contain a null-byte, marking the end of the string.

Parameters

char *str

Pointer to the string.

int value

Value, converted to char, to be located in str.

See Also 
atof, strcat, memcmp, strcmp, strcmpi, strcpy, strlen, strlwr, strupr, sprintf, memcpy, memset

strcmp

Description 

 strcmp(
   char *str1,
   char *str2
);

This function compares str1 and str2 lexicographically.

Parameters

char *str1

Pointer to str1

char *str2

Pointer to str2.

Return Values

This function returns a value indicating their relationship, as follows:

< 0

str1 less than str2.

= 0

str1 identical to str2.

> 0

str1 greater than str2.

See Also 
atof, strcat, memcmp, strcmpi, strcpy, strlen, strlwr, strrchr, strupr, sprintf, memcpy, memset

strcmpi

Description 

 strcmpi(
   char *str1,
   char *str2
);

This function compares the two strings. The comparison is not case-sensitive.

Parameters

char *str1

Pointer to str1

char *str2

Pointer to str2.

Return Values

The return value is less than zero if the string specified in str1 is less than the string specified in str2, is greater than zero if str1 is greater than str2, and is zero if the two strings are equal.

See Also 
atof, strcat, memcmp, strcmp, strcpy, strlen, strlwr, strrchr, strupr, sprintf, memcpy, memset

strcpy

Description 

 strcpy(
   char *str1,
   char *str2
);

This function copies str2, including the terminating null character, to the location specified by str1, and returns str1. The string arguments to this function is expected to contain a null-byte, marking the end of the string. No overflow checking is performed when strings are copied or appended.

Parameters

char *str1

Pointer to str1

char *str2

Pointer to str2.

See Also 
atof, strcat, memcmp, strcmp, strcmpi, strlen, strlwr, strrchr, strupr, sprintf, memcpy, memset

stristr

Description 

 stristr(
   char *Int_str1,
   char *Int_str2
);

This function finds the first occurrence of a substring within a string. The comparison is case insensitive.

Parameters

char *Int_str1

A sequence of characters.

char *Int_str2

String to search for.

Return Values

char* - This function returns a pointer to the first occurrence of Int_str2 in Int_str1, or NULL if Int_str2 does not appear in Int_str1. If Int_str2 points to a string of zero length, the function returns Int_str1.The search does not include terminating null characters.

strlen

Description 

 strlen(
   char *str
);

This function returns the length, in bytes, of str, not including the terminating null-byte.

Parameters

char *str

Pointer to the string.

See Also 
atof, strcat, memcmp, strcmp, strcmpi, strcpy, strlwr, strrchr, strupr, sprintf, memcpy, memset

strlwr

Description 

 strlwr(
   char *str
);

This function converts characters to lowercase ones.

Parameters

char *str

Pointer to the string.

Return Values

This function returns length of a converted string.

See Also 
atof, strcat, memcmp, strcmp, strcmpi, strcpy, strlen, strrchr, strupr, sprintf, memcpy, memset

strrchr

Description 

 strrchr(
   char *str,
   int  value
);

This function returns a pointer to the last occurrence of value (converted to char) in str. The converted character value may be the null character, the terminating null character of str is included in the search. The function returns NULL if value is not found. This function operates on null-terminated strings. The string arguments are expected to contain a null-byte, marking the end of the string.

Parameters

char *str

Pointer to the string.

int value

Value, converted to char, to be located in str.

See Also 
atof, strcat, memcmp, strcmp, strcmpi, strcpy, strlen, strlwr, strupr, sprintf, memcpy, memset

strstr

Description 

 strstr(
   char *Int_str1,
   char *Int_str2
);

This function finds the first occurrence of a substring within a string. The comparison is case sensitive.

Parameters

char *Int_str1

A sequence of characters.

char *Int_str2

String to search for.

Return Values

char* - This function returns a pointer to the first occurrence of Int_str2 in Int_str1, or NULL if Int_str2 does not appear in Int_str1. If Int_str2 points to a string of zero length, the function returns Int_str1.The search does not include terminating null characters.

strupr

Description 

 strupr(
   char *str
);

This function converts characters to uppercase ones.

Parameters

char *str

Pointer to the string.

Return Values

This function returns length of a converted string.

See Also 
atof, strcat, memcmp, strcmp, strcmpi, strcpy, strlen, strrchr, strlwr, sprintf, memcpy, memset