characters left and right from a value

characters left and right from a value

Post by kabbi~thke » Wed, 19 Jul 2006 21:42:39



Hi,
 From a query I get a value returned. From this value I have to extract certain
data. The nr of characters in the value is not alway the same, but I don't need
the last 20 characters and the first 3 characters. So Actually I want the
values leftover after deleting the last 20 characters and the first 3
characters. Is this possible?
 Does someone knows how?

 This is what I use now:

 Because I know most values returned have 30 characters, I know that the value
I need most of the time (but as I said, Not ALL) consist out of 7 characters.

 Here is how I did the extraction to get the right data when the value I need
is seven characters:

 <cfquery name ="qtest" Datasource = "">.
 ...query...
 </query>

 <cfset pnr = left(qtest.wMNAMEUser, 10)>
 <cfset pnr = right(pnr, 7)>

 This works fine for 90 percent of the values I need, because they exist out of
7 valyues. But What I actually would like to do is extract the last 20
characters from the queryvalue and the first three characters from the given
queryvalue, and then put the leftover characters into a value.

 Can this be done? Is there someone who could help me?

 Thank you in advance.

 Kabbi

 
 
 

characters left and right from a value

Post by kabbi~thke » Wed, 19 Jul 2006 22:16:39


Hello,

 I managed to do it like this:

 <cfloop query="qtest">

 <cfif Isdefined("qtest.wMNAMEUser") AND #Len(Trim(qtest.wMNAMEUser))# NEQ 0>
 <cfset pnr = RemoveChars(qtest.wMNAMEUser, 1, 3)>
  <cfset aantal = Len(Trim(pnr))>
  <cfset nr = aantal - 20>
  <cfset pnr = Left(pnr, nr)>
 <!--- <cfset pnr = RemoveChars(Right(aantal, 1, 20))> --->
 <cfoutput>#pnr#<br></cfoutput>
 </cfif>
 </cfloop>

 However I saw that the right part of the value is not always 20 characters
long. So it all becomes a little bit moere difficult.

 This is an example of an total value returned by the query:

 cn=P122356,ou=staff,o=RUG,c=NL  [I want the P122356 here]]

 cn=myname,ou=Adm,o=RUG,c=NL  [myname]

 cn=namename,ou=Staff,ou=FMNS,o=RUG  [namename]

 You can see the total value of characters differs, the first three are always
the same and they have to be removed, but the last characters [till the last
character of the value I need] is not always the same lenght.

 Is it even possible to get the right values [the value between: "cn=" and  
",ou="]?

 Hopefully soemone can help me a little bit with this.

 Regards,

 Kabbi

 
 
 

characters left and right from a value

Post by jdelin » Wed, 19 Jul 2006 22:37:28


Remove the first three characters and then treat the remaining string as a list.

 <!--- get the value between cn and ou --->
 <CFSET foo = "cn=namename,ou=Staff,ou=FMNS,o=RUG">

 <!--- remove the first three characters --->
 <CFSET foo = RemoveChars(foo, 1, 3)>

 <!--- you have a comma-delimited list, the first element of which
 is namename --->
 <CFSET bar = ListFirst(foo)>

 
 
 

characters left and right from a value

Post by wman » Wed, 19 Jul 2006 22:40:00


Hi Kabbi,

Try this:

<CFSET nr =  Mid(qtest.wMNAMEUser,4,Len(qtest.wMNAMEUser)-20)>

Hope this is what you needed?

Cheers / Manu.

 
 
 

characters left and right from a value

Post by drforbin197 » Wed, 19 Jul 2006 23:23:13


We answered this question awhile ago in there forums, what happened?
 
 
 

characters left and right from a value

Post by kabbi~thke » Thu, 20 Jul 2006 21:25:41


HI,

 Yes I'm sorry. I actually already have [and used] a script where this
works.... a little bit overworked, not very awake yesterday....

 Here's the post you mean:

http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=7&...
54171

 This is maybe helpfull to others.

 Regards,

 Kabbi