how would you do a search and replace like this?
<!-- start marker 1 -->
bunch o text
<!-- end marker 1 -->
let's say you want to replace what ever is between the start and end
markers with text from an external file.
would just like some smart tips how to do this with VB.
tia,
mcnewsxp
|
|
0
|
|
|
|
Reply
|
mcnews
|
4/19/2010 2:27:05 PM |
|
mcnews wrote:
> how would you do a search and replace like this?
>
> <!-- start marker 1 -->
>
> bunch o text
>
> <!-- end marker 1 -->
>
> let's say you want to replace what ever is between the start and end
> markers with text from an external file.
> would just like some smart tips how to do this with VB.
mid$() comes to mind...
Simplest would be if can be held in memory to read target into string
variable, find start/end and replace.
Fastest if sizes are considerable could be the memmove() tricks (easily
found by google here or on web as it's been discussed ad nauseum)...
--
|
|
0
|
|
|
|
Reply
|
dpb
|
4/19/2010 2:38:12 PM
|
|
On Apr 19, 8:27=A0am, mcnews <mcour...@mindspring.com> wrote:
> how would you do a search and replace like this?
>
> <!-- start marker 1 -->
>
> bunch o text
>
> <!-- end marker 1 -->
>
> let's say you want to replace what ever is between the start and end
> markers with text from an external file.
> would just like some smart tips how to do this with VB.
>
> tia,
> mcnewsxp
Your question did not describe the source of the text, so I would
limit my suggestion just to the search & replace which is covered by
the replace statement:
text1.text =3D replace(text1.text,"search text", "replace text",start
position, occurrence, compare type)
Finding the start position (start / end marker) can normally be
determined with the use of the InStr statement or omitting the start
position searches the entire value of text1.text
Duke
|
|
0
|
|
|
|
Reply
|
duke
|
4/19/2010 3:22:07 PM
|
|
On Apr 19, 8:27=A0am, mcnews <mcour...@mindspring.com> wrote:
> how would you do a search and replace like this?
>
> <!-- start marker 1 -->
>
> bunch o text
>
> <!-- end marker 1 -->
>
> let's say you want to replace what ever is between the start and end
> markers with text from an external file.
> would just like some smart tips how to do this with VB.
>
> tia,
> mcnewsxp
My apologies.... I reread your question, you did say the text is
coming from an external file.
Anyways, you could apply the replace statement to the buffer area of
the file then write the contents back out to disk.
Duke
|
|
0
|
|
|
|
Reply
|
duke
|
4/19/2010 3:25:12 PM
|
|
On Apr 19, 11:25=A0am, duke <nosp...@3web.net> wrote:
> On Apr 19, 8:27=A0am, mcnews <mcour...@mindspring.com> wrote:
>
> > how would you do a search and replace like this?
>
> > <!-- start marker 1 -->
>
> > bunch o text
>
> > <!-- end marker 1 -->
>
> > let's say you want to replace what ever is between the start and end
> > markers with text from an external file.
> > would just like some smart tips how to do this with VB.
>
> > tia,
> > mcnewsxp
>
> My apologies.... I reread your question, you did say the text is
> coming from an external file.
>
> Anyways, you could apply the replace statement to the buffer area of
> the file then write the contents back out to disk.
>
> Duke
that is pretty much what i am doing now except that i am just looking
for the first marker. what would be the best way to grab the text
between to start and end markers?
|
|
0
|
|
|
|
Reply
|
mcnews
|
4/19/2010 4:22:49 PM
|
|
"mcnews" <mcourter@mindspring.com> wrote
<...>
> that is pretty much what i am doing now except that i am just looking
> for the first marker. what would be the best way to grab the text
> between to start and end markers?
Load the marked text into a string
Load the replaceing text from the file, into a string
Use Instr to find the first and last markers
Build a third string using the first part, file text, and last part of the marked text.
If you're talking several megabytes of text, send the output to a file,
rather than building the third string in memory....
LFS
|
|
0
|
|
|
|
Reply
|
Larry
|
4/19/2010 5:08:40 PM
|
|
On Apr 19, 2:09=A0pm, "Larry Serflaten" <serfla...@usinternet.com>
wrote:
> "mcnews" <mcour...@mindspring.com> wrote
> <...>
>
> > that is pretty much what i am doing now except that i am just looking
> > for the first marker. =A0what would be the best way to grab the text
> > between to start and end markers?
>
> Load the marked text into a string
> Load the replaceing text from the file, into a string
> Use Instr to find the first and last markers
> Build a third string using the first part, file text, and last part of th=
e marked text.
>
> If you're talking several megabytes of text, send the output to a file,
> rather than building the third string in memory....
>
> LFS
i know how to do all but > Load the marked text into a string
am i reading from an input buffer until i see me 2nd marker?
|
|
0
|
|
|
|
Reply
|
mcnews
|
4/19/2010 5:24:54 PM
|
|
mcnews wrote:
....
> i know how to do all but > Load the marked text into a string
>
> am i reading from an input buffer until i see me 2nd marker?
Yet again, I say, Mid$ is your friend
Dim Char1 As String, Char2 As String ! For search char's (or Const)
Dim Str1 As String, MarkStr As String
Dim IdxStrt As Long, IdxEnd As Long
IdxStrt = Instr(Str1,Char1) % First char pos'n in Str1
IdxEnd = Instr(IdxStrt+1,Str1,Char2) % Begin after first
! Do your error checking that both indices are nonzero...
MarkStr = Mid$(Str1,IdxStrt,IdxStrt-IdxEnd+1)
--
|
|
0
|
|
|
|
Reply
|
dpb
|
4/19/2010 5:42:01 PM
|
|
On Apr 19, 1:42=A0pm, dpb <n...@non.net> wrote:
> mcnews wrote:
>
> ...
>
> > i know how to do all but > Load the marked text into a string
>
> > am i reading from an input buffer until i see me 2nd marker?
>
> Yet again, I say, Mid$ is your friend
>
> Dim Char1 As String, Char2 As String ! For search char's (or Const)
> Dim Str1 As String, MarkStr As String
>
> Dim IdxStrt As Long, IdxEnd As Long
>
> IdxStrt =3D Instr(Str1,Char1) =A0% First char pos'n in Str1
> IdxEnd =A0=3D Instr(IdxStrt+1,Str1,Char2) =A0% Begin after first
> ! Do your error checking that both indices are nonzero...
> MarkStr =3D Mid$(Str1,IdxStrt,IdxStrt-IdxEnd+1)
>
> --
with a little tweaking that works great!
thank ya.
|
|
0
|
|
|
|
Reply
|
mcnews
|
4/19/2010 6:13:44 PM
|
|
dpb wrote:
....
> MarkStr = Mid$(Str1,IdxStrt,IdxStrt-IdxEnd+1)
woops...
MarkStr = Mid$(Str1,IdxStrt,IdxEnd-IdxStrt+1)
--
|
|
0
|
|
|
|
Reply
|
dpb
|
4/19/2010 7:22:37 PM
|
|
|
9 Replies
206 Views
(page loaded in 0.129 seconds)
Similiar Articles: DateTimePicker return wrong format - microsoft.public.dotnet ...Now to my question is it possible to get the same format which is this Friday ... I can use string manipulation on this string 4/2/2010 12:57:16 PM to get Friday, April 02 ... XML load problem - microsoft.public.scripting.vbscript... Post Question Groups ... back an exact line # for the failure > to load, and then perform some string manipulation ... manipulating text inside a variable - microsoft.public.windows ...... Post Question Groups ... Visual Basic .NET programming for Beginners - String Manipulation By manipulating Strings ... VBScript String Clean function - remove or replace illegal ...... Post Question Groups ... wonder if the method you > use is suitable for this purpose since string manipulation is ... Array Question Part 2 - microsoft.public.windows.powershell ...... Server.name if(Select-String -pattern ... 2,4,2 ... to get data from a string in to an array - microsoft ... basic question ... samples, C examples ... 2D Array Manipulation ... How can I strip the extensions from filenames in a query ...... Post Question Groups ... straightforward requirement but I have limited awareness of all the string manipulation ... parse data from text field - microsoft.public.access.modulesdaovba ...How to add leading zeros to split field string ... database.itags.org: Microsoft Access question: parse ... to extract fields of text is similar to string manipulation ... Referencing a field in a recordset with a string value - microsoft ...The field name is a string b/c the code is... ... Post Question Groups ... String Manipulation; System API; VB.NET / ASP.NET; Windows ... Format Currency to String with 2 decimal places - microsoft.public ...... Post Question Groups ... Global function Form (If a form global): Category: String & Text Manipulation ... Reading large csv-file and removing duplicates - microsoft.public ...I don't usually suggest using a database for random file manipulation questions, but I think ... Rather than using a HashSet<string>, use a HashSet<byte[]> and store the ... String Manipulation Interview Questions | CareerCup13 Answers. write a function strRemove(char *source, char *remove ) This function will delete all the chars that exist in string remove from array source, number of ... String Manipulation Interview Questions | CareerCup22 Answers. Write a function which determines whether provided string matches specified pattern. Signature: bool is_match(char* text, char* pattern) Classic string manipulation interview questions? - Stack OverflowI am scheduled to have an onsite interview so I am preparing few basic questions. According to the company profile, they are big on string manipulation questions. String Manipulation Question - Microsoft Corporation: Software ...I have a very simple question: I have a string that may say "3x itemname", or "32x itemname". How do I get it to return the number infront of the x? I have ... String Manipulation ยป My Tech InterviewsQuestion: Implement strstr in Java. Find the first instance of a string in another string. Answer: public int Search(String haystack, String needle){ for(int i = 0; i ... 7/31/2012 4:02:12 AM
|