Variable column widths, string lengths in printf-style functions

topic: 

I have been programming in C for quite some time, but until recently I was not aware that you could specify column widths and string limits using variables. I have neither seen this functionality used in any projects until I started working with OpenSER.

Specify a variable column width:

printf("%*d", width, number);

Specify a variable number of characters from a string:

printf("%.*s", width, string);

Proper UDF - Capitalize String as Proper Names

The ufn_Proper() UDF for SQL Server is similar to the VFP Proper() function. It additionally allows to specify a set of delimiters.

$SAMPLECODE$


IF EXISTS (SELECT * FROM sysobjects WHERE name = N'ufn_Proper')
DROP FUNCTION ufn_Proper
GO

Strextract UDF - Retrieves String Between Two Delimiters

The ufn_StrExtract() UDF for SQL Server is similar to the VFP StrExtract() function.

$SAMPLECODE$


-- ufn_StrExtract ---
IF EXISTS (SELECT * FROM sysobjects WHERE name = N'ufn_StrExtract')
DROP FUNCTION ufn_StrExtract
GO

CREATE FUNCTION ufn_StrExtract (
@StrIn varchar(8000),
@StartDelim varchar(128),
@EndDelim varchar(128),
@Flag int=0)

Alines UDF - String Split

The ufn_Alines() UDF for SQL Server is similar to the VFP Alines() function but w/o additional parameters.

$SAMPLECODE$

Pages

Subscribe to The Bereznikers RSS