Trey Copeland
Trey Copeland

Reputation: 3527

How can I extract text before a specific character in a string using Coldfusion?

I have a string that looks like:

5137.02014-10-16T11:26:32-06:001.0.

How can I extract the text or numbers before the first period? It will not always be 4 characters.

EDIT:

After looking at the source code, it appears to be producing this:

<wddxpacket version="1.0">
  <header>
   <data>
     <struct>
     <var name="Logo">
       <string></string>
     </var>
     <var name="ID">
       <number>5137.0</number>
     </var>
     <var name="RLink">
       <string></string>
     </var>
     <var name="DateCreated">
       <datetime>2014-10-16T11:26:32-06:00</datetime>
     </var>
     <var name="showTabs">
       <number>1.0</number>
     </var>
    </struct>
</data> 

I am just trying to extract the ID which would be 5137 in this case.

Thanks!

Upvotes: 1

Views: 1755

Answers (2)

Regular Jo
Regular Jo

Reputation: 5510

With updated information on the structure of the data, this answer is no longer valid.


You can do this

#listfirst(my_number_string,".")#

Upvotes: 2

Leigh
Leigh

Reputation: 28873

Update:

Looks like the input is actually WDDX, rather than a plain text string. Convert it into a CF structure. Then extract the "ID" value by key. No need for parsing strings.

<!--- convert the string into a CF structure --->
<cfwddx action="WDDX2CFML" 
    input="#yourString#" 
    output="result">

<!--- grab the "ID" value --->
<cfdump var="#result.ID#">  

Upvotes: 5

Related Questions