0
Need Help finding a char from a flat file
Community Beginner
,
/t5/coldfusion-discussions/need-help-finding-a-char-from-a-flat-file/td-p/863950
Aug 13, 2008
Aug 13, 2008
Copy link to clipboard
Copied
My CFSCRIPT need to find a character from a flat file.
The flat file look something like this:
20;193236;1;KUMAR;RETESTDEFECT215;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
20;193236;1;DIANE;SMITH;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
20;193236;1;ROBERT;REYES15;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
etc...
I need to determine whether number "20" in the file exist. How can I do this? can anyone help?
<cfscript>
IsRecordExist=Search("fileContent", 20) ?????
</cfscript>
<cfoutput>
#IsRecordexist#
</cfoutput>
The flat file look something like this:
20;193236;1;KUMAR;RETESTDEFECT215;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
20;193236;1;DIANE;SMITH;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
20;193236;1;ROBERT;REYES15;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
etc...
I need to determine whether number "20" in the file exist. How can I do this? can anyone help?
<cfscript>
IsRecordExist=Search("fileContent", 20) ?????
</cfscript>
<cfoutput>
#IsRecordexist#
</cfoutput>
TOPICS
Getting started
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/need-help-finding-a-char-from-a-flat-file/m-p/863951#M79663
Aug 13, 2008
Aug 13, 2008
Copy link to clipboard
Copied
Won't any of the string functions find(), reFind(),
listFind() or
listContains() do what you want done?
listContains() do what you want done?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
alecken
AUTHOR
Community Beginner
,
/t5/coldfusion-discussions/need-help-finding-a-char-from-a-flat-file/m-p/863952#M79664
Aug 13, 2008
Aug 13, 2008
Copy link to clipboard
Copied
I tried this but I got 0 result:
<cfsavecontent variable="fileContents">
20;193236;1;KUMAR;RETESTDEFECT215;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
20;193236;1;DIANE;SMITH;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
20;193236;1;ROBERT;REYES15;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
</cfsavecontent>
<cfscript>
IsRecordExist= Find("fileContents", 20);
</cfscript>
<cfoutput>
#IsRecordExist#
</cfoutput>
RESULT: 0
<cfsavecontent variable="fileContents">
20;193236;1;KUMAR;RETESTDEFECT215;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
20;193236;1;DIANE;SMITH;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
20;193236;1;ROBERT;REYES15;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
</cfsavecontent>
<cfscript>
IsRecordExist= Find("fileContents", 20);
</cfscript>
<cfoutput>
#IsRecordExist#
</cfoutput>
RESULT: 0
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/need-help-finding-a-char-from-a-flat-file/m-p/863953#M79665
Aug 13, 2008
Aug 13, 2008
Copy link to clipboard
Copied
alecken wrote:
>
> <cfscript>
> IsRecordExist= Find("fileContents", 20);
> </cfscript>
>
> <cfoutput>
> #IsRecordExist#
> </cfoutput>
>
> RESULT: 0
>
That would because the string ("fileContents") does not have the string
("20") in it. You put quotes around your variable and didn't put quotes
around the string you wanted to find.
Try find(fileContents,20) or better yet, find(fileContents,"20")
>
> <cfscript>
> IsRecordExist= Find("fileContents", 20);
> </cfscript>
>
> <cfoutput>
> #IsRecordExist#
> </cfoutput>
>
> RESULT: 0
>
That would because the string ("fileContents") does not have the string
("20") in it. You put quotes around your variable and didn't put quotes
around the string you wanted to find.
Try find(fileContents,20) or better yet, find(fileContents,"20")
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
/t5/coldfusion-discussions/need-help-finding-a-char-from-a-flat-file/m-p/863954#M79666
Aug 13, 2008
Aug 13, 2008
Copy link to clipboard
Copied
Also, if would you like to have the number of occurences of
the string "20" in your file, you may try this UDF,
http://cflib.org/udf/FindOccurrences
http://cflib.org/udf/FindOccurrences
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
/t5/coldfusion-discussions/need-help-finding-a-char-from-a-flat-file/m-p/863955#M79667
Aug 14, 2008
Aug 14, 2008
Copy link to clipboard
Copied
The substring is the first parameter in the find() syntax. I
have used sstrg as a general search item below:
<cfsavecontent variable="fileContents">
20;193236;1;KUMAR;RETESTDEFECT215;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_8820;193236;1;DIANE;SMITH;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_8820;193236;1;ROBERT;REYES15;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
</cfsavecontent>
<!--- Specify the item you are searching for --->
<cfset sstrg = 20 />
<!--- Trim to take care of unwanted leading spaces --->
<cfscript>
IsRecordExist= Find(sstrg, LTrim(fileContents));
</cfscript>
<!--- Output result --->
<cfoutput>
<cfif IsRecordExist EQ 0>
<strong>#sstrg#</strong> does not exist in the file.
<cfelse>
The first occurrence of <strong>#sstrg#</strong> is at position #IsRecordExist# in the file.
</cfif>
</cfoutput>
<cfsavecontent variable="fileContents">
20;193236;1;KUMAR;RETESTDEFECT215;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_8820;193236;1;DIANE;SMITH;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_8820;193236;1;ROBERT;REYES15;;STRETE;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_88
</cfsavecontent>
<!--- Specify the item you are searching for --->
<cfset sstrg = 20 />
<!--- Trim to take care of unwanted leading spaces --->
<cfscript>
IsRecordExist= Find(sstrg, LTrim(fileContents));
</cfscript>
<!--- Output result --->
<cfoutput>
<cfif IsRecordExist EQ 0>
<strong>#sstrg#</strong> does not exist in the file.
<cfelse>
The first occurrence of <strong>#sstrg#</strong> is at position #IsRecordExist# in the file.
</cfif>
</cfoutput>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
alecken
AUTHOR
Community Beginner
,
/t5/coldfusion-discussions/need-help-finding-a-char-from-a-flat-file/m-p/863956#M79668
Aug 15, 2008
Aug 15, 2008
Copy link to clipboard
Copied
First I like to say thank you for the responses. I tried the
suggestion and it is working but not as expected especially on case
where the content also have char 20 somewhere lese for example in
case like this:
<cfsavecontent variable="filecontents">
20;193236;1;KUMAR;REYES;;STR;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_2-88.pdf
</cfsavecontent
The char 20 is not only found in the begining of the string but may also exist in the middle of the string:Contract_ 20080715-2_10093_2-88.pdf and may be somewhere else.
I only need to detect the first char from my feed to make sure if this record exist.
<cfsavecontent variable="filecontents">
20;193236;1;KUMAR;REYES;;STR;;;SPRINGFIED;MA;01111;;;Contract_20080715-2_10093_2-88.pdf
</cfsavecontent
The char 20 is not only found in the begining of the string but may also exist in the middle of the string:Contract_ 20080715-2_10093_2-88.pdf and may be somewhere else.
I only need to detect the first char from my feed to make sure if this record exist.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/need-help-finding-a-char-from-a-flat-file/m-p/863957#M79669
Aug 15, 2008
Aug 15, 2008
Copy link to clipboard
Copied
several options for you:
a) cfif listfirst(textline, ";") is "20"
b) cfif left(textline, 2) is "20"
c) cfif refind("^20\.*", textline)
which one to use depends on what else you are doing with your text...
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
a) cfif listfirst(textline, ";") is "20"
b) cfif left(textline, 2) is "20"
c) cfif refind("^20\.*", textline)
which one to use depends on what else you are doing with your text...
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
alecken
AUTHOR
Community Beginner
,
LATEST
/t5/coldfusion-discussions/need-help-finding-a-char-from-a-flat-file/m-p/863958#M79670
Aug 19, 2008
Aug 19, 2008
Copy link to clipboard
Copied
I like to thanks everyone for helping!!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

