Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need some Improvement (STRTRAN Function)
Message
From
13/11/2017 10:40:44
 
 
To
13/11/2017 10:14:29
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01655516
Message ID:
01655548
Views:
39
Exactly, STREXTRACT() but Since I have Data in long strings not in Table I cant use STREXTRACT() perhaps. That is why I have taken the the contents of file in String using FILETOSTR()




>If I understood it correctly, simply use STREXTRACT() to determine the string to be replaced.
>
>
>LOCAL Prefix AS String
>LOCAL Postfix AS String
>LOCAL ReplacedText AS String
>LOCAL CurrentText AS String
>LOCAL FileContents AS String
>
>m.Prefix = '_123456789_123456789'
>m.Postfix = "/MediaBox"
>m.FileContents = m.cFile
>
>Select StringobjectNo
>SCAN
>	m.ReplacedText = ALLTRIM(STR(StringobjectNo.FObjectno)) + " 0 obj <</Type /Page /Parent 2 0 R " + m.Postfix
>	m.CurrentText = STREXTRACT(m.FileContents, m.Prefix, m.Postfix, 1, 4)
>	m.FileContents = STRTRAN(m.FileContents, m.CurrentText, m.ReplacedText, 1, 1)
>ENDSCAN
>
>m.cFile = m.FileContents
>
>
>>Sir,
>>
>>I have Check Stuff() Function.
>>
>>Also, it not the case of case Sensitive issue. It is related to the length Up to which Position Text is to be extracted.
>>
>>What I mean to say is that I am Not able to Extract the exact Required string Because I have Taken the Fixed Length as 47 from the start position. However, there are cases where my Required String ends at 48 or 56 Length or may be at 100 Length from the starting position i.e '_123456789_123456789.
>>
>>Real Example
>>
>>'_123456789_123456789_123456789__0 R /MediaBox ['
>>Since the last letter 'x' i.e Last letter of 'Mediabox' is within 47 length of starting point it is working Fine
>>
>>BUT
>>
>>'_123456789_123456789_123456789__ 2 0 R /MediaBox ['
>>Since the last letter 'x' i.e Last letter of 'Mediabox' is beyond 47 length of starting point it is not working
>>
>>
>>'_123456789_123456789_123456789__ 8596__ 123456789__ 2638328_2 0 R /MediaBox ['
>>Since the last letter 'x' i.e Last letter of 'Mediabox' is beyond 47 length of starting point it is not working
>>
>>
>>This is because I am assuming that the position of 'x' 'Mediabox' will be between 1 and 47 i.e the length of the string will not be More than 47. However in cases it may be beyond 47 also. If I change 47 to say 100 it will for the above two cases also. But there are cases where we dont know the exact length of the string.
>>
>>For Extracting The Text I am not using the correct Logic
>>
>>cFindMissingText=SUBSTR(cFile,nMissingObjectStartPosition,47+8) && 47 the start point of Mediabox  i.e M and 8 for the length of 'Mediabox' 
>>
>>
>>I am looking for a syntax or command to extract each case that starts with '_123456789_123456789 and ends with 'Mediabox' (irrespective of its length ) and change each such extracted Text/string with my specific desired Text
>>
>>That's it.
>>
>>Regards
>>
>>
>>>Showing the code which does not work is not very helpful. Please reread what I ask for. I prefer do analyze the problem without looking at your code.
>>>
>>>>Sir,
>>>>Yes, I have checked stuff() but dont think it will be useful.
>>>>
>>>>I just Need the start position and the End position of the string so that I could Extract That string using SUBSTR() and Replace it using STRTRAN()
>>>>
>>>>Here is an Example
>>>>
>>>>I have a File in which there is Text. In Between These Texts there are many string which Starts with '_123456789_123456789' and Ends with 'Mediabox' for example
>>>>
>>>> 'JJ2klo_123456789_123456789_i2iuwk9kkqs92uksk_Mediabox KK'
>>>> '_123456789_123456789_i2iuwk9kkqs92uksk29083nsdjkw92wdkw9_Mediabox IOMJ'
>>>> 'Jijk_123456789_123456789_i2iuwk9kkqs92uksk29083s__qwojqkknsdjkw92wdkw9_54212Mediabox'
>>>> '_123456789_123456789_i2iuwk9kkqs92uksk29083s__qwojqkknsdjkw92wdkw9_54212Mediabox'
>>>>
>>>>I need to Extract the String between _123456789_123456789 and Mediabox i.e for example _123456789_123456789_i2iuwk9kkqs92uksk_Mediabox in first case and Replace it with my Desired string.
>>>>
>>>>Here is the code I am using, which is working fine as long as the Length of the string is not too long as I have taken 47 from start position. If the text Mediabox is far beyond it is not working correctly. My Code has a fault that it dependent on Fixed Length of 47 though the Length of the entire string may be up to 100 or 150.
>>>>
>>>>
>>>>Select StringobjectNo
>>>>SCAN
>>>>cReplacedText=ALLTRIM(STR(FObjectno))+" 0 obj <</Type /Page /Parent 2 0 R /MediaBox"
>>>>nMissingObjectStartPosition=AT('_123456789_123456789',cFile,1)
>>>>cFindMissingText=SUBSTR(cFile,nMissingObjectStartPosition,47)
>>>>nMissingObjectEndPosition=AT('MediaBox',cFindMissingText,1)+8
>>>>cMissingText=SUBSTR(cFile,nMissingObjectStartPosition,nMissingObjectEndPosition)
>>>>cFile=STRTRAN(cFIle,cMissingText,cReplacedText,1,1)
>>>>ENDSCAN
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>Have you checked the Stuff() function? If that doesn't help, please provide some realistic samples of what you have, and what you want it replaced with.
>>>>>
>>>>>>Sir,
>>>>>>The problem is not related to Size. The may be long but not that much that it will be a file Size.
>>>>>>
>>>>>>There is a Substitution problem as I have Limit the Length to 47. So if the length is around say 100, it does not substitute it properly.
>>>>>>
>>>>>>My Requirement is Just to find out the starting position of _123456789_123456789 and Starting Position of Mediabox 'M' for every such type of strings in a File.
>>>>>>There can be N Number of such strings in the entire File. 'Mediabox' will always be after _123456789_123456789.
>>>>>>
>>>>>>Example of my string in Text File
>>>>>>
>>>>>>'KUMRA1521521_123456789_123456789_Ym30251_7jgu92l02klk414_5268YYU**1HnY_/Mediabox OPLOHT&@JWFK_IWKWM' && I need 13 for _123456789_123456789_ and 73 for 'M' (Mediabox). Or 13 & 80 ('x' Mediabox) so that I can get the desired string between using SUBSTR()
>>>>>>
>>>>>>Ultimately I am looking to Replace '_123456789_123456789_Ym30251_7jgu92l02klk414_5268YYU**1HnY_/Mediabox' with my desired string which I need to Replace.
>>>>>>
>>>>>>Thanks
>>>>>>
>>>>>>
>>>>>>>If the file is to big, you may have to read it in smaller chunks using low level file functions. Check Fread() in Help, and the other functions mentioned on that topic. It may also be much faster.
>>>>>>>
>>>>>>>>Using FILETOSTR() I have Taken the extract of a file in a String.
>>>>>>>>
>>>>>>>>I Need to Replace certain strings in the entire file with my New String.
>>>>>>>>
>>>>>>>>The string which I need to Replace starts with '_123456789_123456789' and Ends with 'MediaBox' i.e the starting point of the string will always be
>>>>>>>>_123456789_123456789 followed by some Variable Part and the last words in the will always be 'MediaBox'. The Length of the string could be any.
>>>>>>>>
>>>>>>>>Example of such string are
>>>>>>>>
>>>>>>>>'_123456789_123456789_Ym30251_414_5268YYUHnY_/Mediabox
>>>>>>>>
>>>>>>>>Or
>>>>>>>>
>>>>>>>>'_123456789_123456789_Ym30251_7jgu92l02klk414_5268YYU**1HnY_/Mediabox
>>>>>>>>
>>>>>>>>
>>>>>>>>I am using the Following code, which is working fine where the Length of String is Not too Long
>>>>>>>>
>>>>>>>>
>>>>>>>>Select StringobjectNo
>>>>>>>>SCAN
>>>>>>>>cReplacedText=ALLTRIM(STR(FObjectno))+" 0 obj <</Type /Page /Parent 2 0 R /MediaBox"
>>>>>>>>nMissingObjectStartPosition=AT('_123456789_123456789',cFile,1)
>>>>>>>>cFindMissingText=SUBSTR(cFile,nMissingObjectStartPosition,47)
>>>>>>>>
>>>>>>>>* Here I Have Taken Length as 47 assuming that the 1st Word of 'Mediabox' will be included within the span of 47, However, this is not always the case as there can be Strings whose Length can be Far far more than 47. So I need some Logical Improvement on This part particularly. 
>>>>>>>>
>>>>>>>>*My overall Object is to Extract the String which is  '_123456789_123456789.....Mediabox' and replace it with cReplacedText.
>>>>>>>>
>>>>>>>>nMissingObjectEndPosition=AT('MediaBox',cFindMissingText,1)+8
>>>>>>>>
>>>>>>>>cMissingText=SUBSTR(cFile,nMissingObjectStartPosition,nMissingObjectEndPosition)
>>>>>>>>
>>>>>>>>cFile=STRTRAN(cFIle,cMissingText,cReplacedText,1,1)
>>>>>>>>ENDSCAN
>>>>>>>>
>>>>>>>>
>>>>>>>>The above code is working fine for short length of strings but if the length of string is too long, it fails to perform.
>>>>>>>>
>>>>>>>>Kindly Suggest How to do this.
>>>>>>>>
>>>>>>>>Thanks
Harsh
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform