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

Need Help finding a char from a flat file

Community Beginner ,
Aug 13, 2008 Aug 13, 2008
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>




TOPICS
Getting started
688
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
LEGEND ,
Aug 13, 2008 Aug 13, 2008
Won't any of the string functions find(), reFind(), listFind() or
listContains() do what you want done?
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 Beginner ,
Aug 13, 2008 Aug 13, 2008
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



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
LEGEND ,
Aug 13, 2008 Aug 13, 2008
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")

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
Advocate ,
Aug 13, 2008 Aug 13, 2008
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
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
Participant ,
Aug 14, 2008 Aug 14, 2008
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>
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 Beginner ,
Aug 15, 2008 Aug 15, 2008
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.

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
LEGEND ,
Aug 15, 2008 Aug 15, 2008
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/
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 Beginner ,
Aug 19, 2008 Aug 19, 2008
LATEST
I like to thanks everyone for helping!!
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