Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Pickup first characters in a string
Message
De
23/08/2002 13:08:43
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00692996
Message ID:
00693030
Vues:
15
>I am trying to pick out first character in a string for example:
>
>Chief Probation Officer
>
>I need to return
>
>CPO
>
>
>I there a quick way of doing this, I will need to perform this operation on hundreds of strings. If there is no straight forward way of doing this then do I put each character in an array and search the array ?
>
>Thanks
>Nick Patel

Nick,

An alternative. Surely not the fastest, but I like it
*---------------------------------------------------------------------------
function yyy1()

	local RegExp, Match
	RegExp = CreateObject('VBScript.RegExp')
	RegExp.Global = TRUE
	RegExp.IgnoreCase = FALSE
	*RegExp.Pattern = '[^\s]+\s*'
	*RegExp.Pattern = '\w+\s*'
	RegExp.Pattern = '\w+[^\w]*'
	
	select	d_name, ;
		padr(yyy2(RegExp, d_name), 16) as initials ;
		from Dossier 
endfunc
*---------------------------------------------------------------------------
function yyy2(RegExp, s)

	local Match, Out
	Out = ''
	Match = RegExp.Execute(s)

	for i = 0 to Match.Count - 1
		Out = Out + left(Match.Item[i].Value,1)
	endfor
	return Out
endfunc
*---------------------------------------------------------------------------
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform