Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string cleanup question, RegEx/Find

Status
Not open for further replies.

bdog2020

Instructor
Jun 16, 2003
203
0
0
US
Hi there,
I've got some data that's coming in from another system and ends up being in one field looking a bit like this:
;tweed;cotton;;

I'm just needing to trim the list so there's not a leading or trailing semicolon, so I end up like this:
tweed;cotton

But, having a hard time with the right combo of RegExpression or find operations to do that.

thanks,
MB
 
1. How are you actually using the value
2. What about extra ";" in between elements, like "tweed;;cotton;"?

I ask because CF list functions ignore empty elements. So if you wanted to ignore all empty elements, you could just use list functions.

----------------------------------
 
thanks cfSearching.

Yeah, I just want to display it, minus the ;'s at the beginning and end (but you bring up a good point about the ones possibly in the middle). It is one field but comes in from another data source with 4 fields, that are all dumped into my 1 field. I can't change how it's coming in for the moment, and it's just separating with a semicolon. So, it could be a variety of things, depending on blank values in particular positions of the 4 fields.

I was just trying to split it using ArrayToList, that seemed possibly promising.
 
Hmm. Well if you need to do any matching with the external system you may want to preserve the extra ";"'s. Though you could easily use list functions for display purposes.

But why store it in 1 field? If you anticipate doing any queries at all on the information, you might want to rethink that. Delimited fields can be an absolute nightmare to query.

----------------------------------
 
you're right on all counts. We're currently just using it to display, I might see if I can have the import approach changed.

I got what I need just by doing some of this stuff:

<cfoutput>
<cfset txt=';;;plaid;;;tweed;;cotton;;;'>

<cfset MB=ListToArray(txt,";") />

<cfdump var="#MB#">

<cfloop from=1 to="#arraylen(MB)#" index="i">
<cfif i EQ arraylen(MB)>
#MB#
<cfelse>
#MB#;
</cfif>
</cfloop>

</cfoutput>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top