Dec 192017
 
Various string routines in Turbo C.
File JSTR.ZIP from The Programmer’s Corner in
Category C Source Code
Various string routines in Turbo C.
File Name File Size Zip Size Zip Type
JSTRING.C 10946 2014 deflated
JSTRING.DOC 12189 2540 deflated
JSTRING.H 831 194 deflated

Download File JSTR.ZIP Here

Contents of the JSTRING.DOC file




JSTRING - String Handling Routines PAGE 1



DISCLAIMER

The Author makes no warranty as to the suitability or correctness
of the software in whole or in part for any particular purpose.




JSTRING

JSTRING is a library of string handling routines distributed
under the shareware concept. You may use the software to
determine if it meets your needs. If you then decide to continue
using the software you pay a license fee to the author. The
license fee for this package is $10.00. This fee entitles you to
use the software royalty free.


If you choose to license JSTRING, please send the $10.00 license
fee to:

Bill Jefferson Jr.
P.O. Box 70026
Albany, Ga. 31707-0001


Whatever you decide to do, please distribute this software to any
bulletin boards you wish. I may be contacted at CIS[73117,2075].


































JSTRING - String Handling Routines PAGE 2



JSTRING includes 17 string handling functions to make string
handling easier for you. They add the ability to:

Insert one string into another.
Delete a portion of a string.
Remove leading or trailing spaces from a string.
Pad a string on the right or left with spaces.
Pad a string on the right or left with a user defined character.
Truncate a string at a certain position.
Replace part of a string with another string.
Swap a specified number of characters of two strings.
Retrieve part of a string into another with NULL appended.
Substitute a string for part of another.
Center a string in a field with blank spaces.
Center a string in a field with a user defined character.
Insert spaces between the characters of a string.
Insert defined characters between the characters of a string.



The following files are included as part of the package:

JSTRING.C - The source for JSTRING
JSTRING.H - The header for JSTRING
JSTRING.DOC - This document





































JSTRING - String Handling Routines PAGE 3




char* strrtrm(char *string);
------------------------------------------------------------

This function strips all trailing spaces from the NULL terminated
string pointed to by *string. It returns a pointer to the new
string so that functions can be stacked.

EXAMPLE:

strrtrm(strltrm(string));













char* strltrm(char *string);
------------------------------------------------------------

This function strips all leading spaces from the NULL terminated
string pointed to by *string. It returns a pointer to the new
string so that functions can be stacked.

EXAMPLE:

strrtrm(strltrm(string));




























JSTRING - String Handling Routines PAGE 4



char* strrpad(char* string, unsigned size);
------------------------------------------------------------

This function pads the string pointed to by *string to size
length on the right. It returns a pointer to the newly padded
string so that functions can be stacked. If the length of the
string is already greater than size, this function simply returns
a pointer to the untouched string. An example use of this
function would be to increase the size of a 15 character string
to a thirty character long string for use as a key in indexed
file access. The function call strrpad(mystring, 30) would
append 15 blank characters to the string *mystring if *mystring
where already 15 characters long.









char* strlpad(char* string, unsigned size);
------------------------------------------------------------

This function pads the string pointed to by *string to size
length on the left. It returns a pointer to the newly padded
string so that functions can be stacked. If the length of the
string is already greater than size, this function simply returns
a pointer to the untouched string. The function call
strrpad(mystring, 30) would prepend 15 blank characters to the
string *mystring if *mystring where already 15 characters long.






























JSTRING - String Handling Routines PAGE 5



char* strrpadch(char* string, unsigned size, char ch);
------------------------------------------------------------

This function is exactly like the JSTRING function strrpad() with
the exception that it has the extra character parameter ch which
will be used to pad the string in place of blank spaces.














char* strlpadch(char* string, unsigned size, char ch);
------------------------------------------------------------

This function is exactly like the JSTRING function strlpad() with
the exception that it has the extra character parameter ch which
will be used to pad the string in place of blank spaces.




































JSTRING - String Handling Routines PAGE 6



char* strdelete(char* string, unsigned pos, unsigned count);
------------------------------------------------------------

This function will delete part of a string. It deletes count
characters of *string beginning at pos. If pos is greater than
the length of *string then this function will return a pointer to
the untouched string. If pos+count is greater than the length of
the string then it will only delete to the end of the string.
This function returns a pointer to the new string so that
functions can be stacked. Please note that pos = 0 is the first
character of the string as in normal C character arrays.










char* strinsert(char* dest, char* source, unsigned pos);
------------------------------------------------------------

This function will insert the string pointed to by *source into
the string pointed to by *dest starting in front of the character
at position pos. Note that pos = 0 is the first character in the
string *dest. It returns a pointer to *dest. If pos is greater
than the length of dest then the string pointed to by *dest is
left untouched.
































JSTRING - String Handling Routines PAGE 7



char* strtrunc(char* string, unsigned newlen);
------------------------------------------------------------

This function truncates a string to newlen length and returns a
pointer to the truncated string. If newlen is greater than the
length of *string than this function simply returns a pointer to
the untouched string.























































JSTRING - String Handling Routines PAGE 8



char* strreplace(char* dest, char* source);
------------------------------------------------------------

This string replaces characters in *dest with characters in
*source. It returns a pointer to *dest. If *source is longer
than *dest then this function will only replace up to the
existing characters in *dest, it will not alter the length of
*dest. An example usage to replace the characters starting at
the 4th character position in *dest with the string "ABC" would
be strreplace(string + 3, "ABC").












int strswap(char* string1, char* string2, unsigned count);
------------------------------------------------------------

This function will swap the first count characters of *string1
and *string2. If the strings are of unequal length and the
parameter count is greater than the length of the shorter string
then only as many characters as exist in the shorter string will
be swapped. The function returns 0 on failure and non-zero on
success.































JSTRING - String Handling Routines PAGE 9



char* substring(char* dest, char* source, unsigned count);
------------------------------------------------------------

This places the first count characters of *source into *dest and
NULL terminates *dest, returning a pointer to *dest. If count is
greater than the length of source then only as many characters as
exist in source will be copied. Remember that you can add an
offset to the string pointer if you want a portion of the string
*source not starting at source[0].













char* strsubst(char* dest, char* source, unsigned count);
------------------------------------------------------------

This function will replace count characters of *dest with the
string *source. This is accomplished by first deleting count
characters of *dest then inserting *source into *dest. This
function returns a pointer to *dest.

EXAMPLE:

dest = "ABCDEFGHIJKL" /* This is what *dest initially is */

strsubst(dest + 3, "VWXYZ", 3);

dest = "ABCVWXYZGHIJKL" /* This is what *dest now is */

























JSTRING - String Handling Routines PAGE 10



char* strcenter(char* string, unsigned width);
------------------------------------------------------------

This functions centers a string in a field of size width by
padding it on the left and right with blank spaces. If width is
less than the size of the string *string then *string will be
unaffected. The function returns a pointer to the string
*string. If an odd number of spaces would be required to center
the string then the extra space will be prepended to the string.











char* strcenterch(char* string, unsigned width, char ch);
------------------------------------------------------------

This function is identical to the function strcenter() with the
exception that it requires an extra parameter ch. This parameter
contains a character which will be used for padding the string in
place of blank spaces.



































JSTRING - String Handling Routines PAGE 11



char* strsep(char* string);
------------------------------------------------------------

This function will insert a space between each of the characters
of a string. It will not insert a space before the first
character or after the last character of a string.

EXAMPLE:

strsep(string);

BEFORE: "ABCDE"
AFTER: "A B C D E"










char* strsepch(char* string, char ch);
------------------------------------------------------------

This function is exactly like the strsep function with the
exception that parameter ch is used in place of a blank space.

EXAMPLE:

strsepch(string, '*');

BEFORE: "ABCDE"
AFTER: "A*B*C*D*E"



























 December 19, 2017  Add comments

Leave a Reply