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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace a specific line in a memo field 2

Status
Not open for further replies.

Eguy

Programmer
Dec 22, 2000
566
US
Riddle me this Batman.

I need to replace a specific line in a memo field.
I know the line number, so I can do the following:

lcString = MLINE(methods,lnLineNum)
lcString = STRTRAN(lcString,lcExpSought,lcReplacement)

I know that STRTRAN will work on a memo field, but I don't know how many previous occurences of lcExpressionSought there might be.
I suppose I could loop through the field and count them, but I would like it to be a little more glamorous. Is there a way to just stuff lcString back to where it came from?

Please be kind, its early Sunday, and I have a bad case of "last night".[morning]

TIA
Ed


Please let me know if the suggestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.
smallbug.gif
 
I do not fully understand what you are trying to do.

are you trying to find how may occuances of a strin inside a memo? or trying to find how many occurances of a string in the data base?

functions like RAT( ) may help depending on yur needs. Attitude is Everything
 
HI

I think you are looking for

cExpressionSearched = memoField && methods ?
myCount = OCCURS(cSearchExpression, cExpressionSearched)

If OCCURS is not what you are looking for..
you can look into the following commands..
AT, ATC, ATCC, AT_C

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Thanks guys!
Here's the poop. Maybe I can explain this better(?)

In a memo field there is a word, lets say "Contact". Contact may appear many times in this memo field. The user wants it changed on line 98.
So I:
lcString = MLINE(methods,98)
lcString = STRTRAN(lcString,"Contact","SomeNewWord")

Now I want to put lcString back into the memo field at line 98.

If I knew that this was the 5th occurence of "Contact" I could:

STRTRAN(lcstring,"Contact","SomeNewWord",5,1)

But I dont know how many times "Contact" appears before or after line 98.
I guess what I'm looking for is the opposite of MLINE, i.e PUT line 98 instead of GET line 98.

I could loop through the field counting "Contact"s until I get to line 98 but that kind of kludgy, I was hoping for something better.

Damn, my head hurts!

BTW - Welcome back ramani

Ed



Please let me know if the suggestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.
smallbug.gif
 
why aren't you letting the user eidt the text with a editbox or rtfedit box?

or just use the STRTRAN( ) on the whole memo and not just part of it.

Attitude is Everything
 
danceman;

Oh if it was that easy!
But "if its not in the specs, its not an option."

Ed Please let me know if the suggestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.
smallbug.gif
 
HI

lcString = MLINE(methods,lnLineNum)
lcString = STRTRAN(lcString,lcExpSought,lcReplacement

LOCAL cNewMemo, nLines
nLines = MEMLINES(methods) && Number of lines
cNewMemo = ""

FOR gnCount = 1 TO nLines && Loop for # of lines
IF gnCount = lnLineNum
cNewMemo = cNewMemo+lcString
ELSE
cNewMemo = cNewMemo+MLINE(notes,gnCount)
ENDIF
NEXT
REPLACE methods WITH cNewMemo

Hope this helps you :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Thanks ramani.

That looks like it will do the trick.

Ed Please let me know if the suggestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.
smallbug.gif
 
If you know the length of the line before and after the replacement you could use _mline as offset where to replace

_mline = 0
lcString = MLINE(methods,lnLineNum)
lLen = LEN(lcString)+2
lcString = STRTRAN(lcString,lcExpSought,lcReplacement)
REPLACE methods WITH SUBST(methods,1,_mline) + lcString + SUBST(methods,_mline + lLen)

Be careful with my code, I'm not an expert but the point is that you get the offset within your memo-field

Just another way :)
Andreas
 
HI Andreas,
That is a good idea. My Star to you. But I would like to polish it for reasons stated. Note that _mline returned offset number includes the total number of characters to the end of the line returned and not as you have assumed (to the beginning of the string)

And

Hi Ed.. I would go about this... in the following way suggested at the end.

In fact MLINE(method,nLineNumber) trims any trailing spaces from the line specified with nLineNumber. So as a consequence, all SPACES used and falling at the end of each MLINE() returned string will be added in my above example without such trailing spaces. This could end up disturbing the earlier saved message. This will be a problem, when word wrap is .t... because almost every line could end up with a space character. For the same reason, Andreas idea could be used to develop the function for your purpose.

Suggestion....
*************************************************
LOCAL lbString, leString, lcString, lnLen

lbString = "" && Begin Part of String
lcString = "" && Part of String to be changed
lcString = "" && final part of the string
_mline = 0

IF lnLineNum > 1
lbString = MLINE(methods,lnLineNum-1)
lbString = LEFT(methods,_mline)
ELSE
lbString = ""
ENDIF

lcString = MLINE(methods,lnLineNum)
lnLen = LEN(methods) - LEN(lbString) - LEN(lcString)
leString = RIGHT(methods,lnLen)

lcString = STRTRAN(lcString,lcExpSought,lcReplacement)

REPLACE methods WITH lbString+lcString+leString
***********************************************

Hope this simplify the whole thing :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top