Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Split String By specific character in cfscript

New Here ,
Apr 30, 2014 Apr 30, 2014

Hi I want to split string(7<>2,,3<>6<>0.6) by specific character(<>) and store it in array...like c# code :

//whwre dataList=7<>2,,3<>6<>0.6

string[] wordsStrings = Regex.Split(dataList, "<>"); 

              

7.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Apr 30, 2014 Apr 30, 2014

You want to use ColdFusion's ListToArray function.  Treat the <> as a list delimiter.  The important part here is setting the last argument to true, for the multiCharacterDelimiter argument.

dataList = "7<>2,,3<>6<>0.6";    

wordsStrings = listToArray(dataList, "<>", false, true);

Translate
Engaged ,
Apr 30, 2014 Apr 30, 2014

You want to use ColdFusion's ListToArray function.  Treat the <> as a list delimiter.  The important part here is setting the last argument to true, for the multiCharacterDelimiter argument.

dataList = "7<>2,,3<>6<>0.6";    

wordsStrings = listToArray(dataList, "<>", false, true);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2014 Apr 30, 2014

Shraddha Prajapati wrote:

string[] wordsStrings = Regex.Split(dataList, "<>");  

That is a bit confusing. Do you mean this:

String[] wordsStrings = dataList.split("<>")

or, its equivalent,

regex = "<>";

String[] wordsStrings = dataList.split(regex);

If so, you already have one solution, Duncancumming's. Another is:

<cfscript>

dataList = createobject("java","java.lang.String").init("7<>2,,3<>6<>0.6");

wordsStrings = dataList.split("<>");

</cfscript>

<cfdump var="#wordsStrings#">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 04, 2014 May 04, 2014
LATEST

<cfscript>

dataList = createobject("java","java.lang.String").init("7<>2,,3<>6<>0.6");

wordsStrings = dataList.split("<>");

</cfscript>

<cfdump var="#wordsStrings#">


Its also correct answer....

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources