|
Hi,
this is what I meant in pseudo-code (I cant help it if it looks very much like C#);
myText is the string to be manipulated.
int startIndex=myText.IndexOf(theStringThatMarksTheBeginOfReplace);
if (startIndex>=0) {
int endMarkLen=theStringThatMarksTheEndOfReplace.Length;
int endIndex=myText.IndexOf(theStringThatMarksTheEndOfReplace, startIndex);
if (endIndex<0) myText=text.Substring(0,startIndex);
else myText=myText.Substring(0,startIndex)+myText.SubString(endIndex+endMarkLen);
}
That should do it. I suggest you read MSDN on any method you are unfamiliar with.
|
|
|
|
|
I got another question. If 1 line of text contain 2 "V", i would like to replace those char or text that start with second "V" until end of the line (vbNewLine) with " ". How to do it?
For substring(first_parameter, second_parameter), may i know what is the purpose of second_parameter?
|
|
|
|
|
If you want to find the second occurence, the easiest way is first find the first occurence,
if found, now look for the second (using the start parameter carefully, otherwise
you end up finding the first again); then if found, do what you intended to do.
A lot of methods have (or optionally have) both a start and a length, which means
do it from start up to start+length-1; so substring(start, length) copies part of
a string, with at most length chars copied, the ones in the range [start, start+length-1]
or less, if there arent that many.
You urgently need to get the habit of reading the documentation, either the
local copy of MSDN that comes with Visual Studio, or the MSDN web site that described
everything Microsoft has. Forums like these are not meant for duplicating the
Microsoft documentation.
|
|
|
|
|
If you want to find the second occurence, the easiest way is first find the first occurence,
if found, now look for the second (using the start parameter carefully, otherwise
you end up finding the first again); then if found, do what you intended to do.
A lot of methods have (or optionally have) both a start and a length, which means
do it from start up to start+length-1; so substring(start, length) copies part of
a string, with at most length chars copied, the ones in the range [start, start+length-1]
or less, if there arent that many.
You urgently need to get the habit of reading the documentation, either the
local copy of MSDN that comes with Visual Studio, or the MSDN web site that described
everything Microsoft has. Forums like these are not meant for duplicating the
Microsoft documentation.
And if you need a tutorial, I recommend you look for an introductory book on C#
in your local book shop or at Amazon's web site.
|
|
|
|
|
Dim textdelimiter As String<br />
textdelimiter = " "<br />
<br />
Dim splitout() = Split(TextLineContent, textdelimiter)<br />
<br />
Dim i As Integer<br />
<br />
For i = 0 To UBound(splitout)<br />
<br />
Dim startIndex As Integer<br />
startIndex = splitout(i).IndexOf("V")<br />
<br />
If startIndex >= 0 Then<br />
<br />
Dim endMarkLen = (splitout(i).Length)<br />
<br />
Dim endIndex = splitout(i).IndexOf(splitout(i), startIndex)<br />
<br />
Dim SecondstartIndex As Integer<br />
SecondstartIndex = splitout(i).IndexOf("V", startIndex)<br />
<br />
If (SecondstartIndex >= 0) Then<br />
splitout(i) = splitout(i).Substring(0, SecondstartIndex)<br />
Else<br />
If (endIndex < 0) Then<br />
<br />
splitout(i) = splitout(i).Substring(0, startIndex)<br />
<br />
Else<br />
splitout(i) = splitout(i).Substring(0, startIndex) + splitout(i).Substring(endIndex + endMarkLen)<br />
<br />
End If<br />
End If<br />
<br />
End If<br />
<br />
SplitTextLineContent += Trim(splitout(i)) & " " <br />
<br />
Next i
Hi,
It didn't work. i tried to find the second occurance of "V" and want to store the array from 0 to the second occurance of "V". I have already struggled for few hours.
|
|
|
|
|
Hi,
several comments:
1.
please use the PRE tag to show some code, it preserves indentation, makes things
much more readable on this forum
2.
why does your code contain a dozen splitout(i) ?
it would be much better to use a variable to hold this, say
Dim split As String
split=splitout(i)
this improves readability inside your IDE as well as on this forum
3.
first bug: endMarkLen must equal the length of the thing that marks the end of what you search,
so you can skip it; it could be 1 or 2 (for length of vbCrLf), it certainly is NOT equal
to split.Length
4.
second bug: you search in the wrong order, you must look for V, then for second V,
then for the end-of-line; there is no other way that is guaranteed to work.
Actually looking for a second V only adds 2 lines to the program you had before !
5.
if things dont work as intended, you must search the bugs, that is called debugging.
Lots of people will tell you to use a debugger for that; I tell you to (temporarily) add
some output statements to your code, showing the content of your variables at different
locations in your code.
It may seem like a bit of extra work, the advantage is you get the relevant information
one after another, listed sequentially (as opposed to a debugger that lets you peek into
just everything, but makes it more diffictult to see many things at once, especially
values before and after something has happened.
Hence add "log statements" and study the log; in this case, show startIndex, endIndex,
etc. and check them manually.
6.
And always true: if something does not work as intended, and it seems difficult to manage,
trim it to something smaller that still fails, but is easier to analyze; then debug,
find the mistake, learn from it, and go back to the bigger thing.
Good luck
|
|
|
|
|
Forgot to add: normally a Replace method (say String.Replace) replaces every occurence,
so "aha".Replace("a","o") yields "oho"
dont know what your Replace method does, if it replaces only one occurence, then maybe
you should choose a different name (ReplaceOnce ?).
|
|
|
|
|
Thanks. Problem solved.
|
|
|
|
|
i heve problem in implementation numerical method and matrix equation to create in visual basic
how to make inverse matrix 4x4 in visual basic code
give some example program and code
in another time i want show you my problem in example
I hope to get experince in programming visual basic and c++ and and i hope you want to discuse with me..
|
|
|
|
|
What problem? What error it says. We cannot help you without seeing your code.
SSK.
|
|
|
|
|
Vri SSK wrote: What problem?
I am guessing that he wants to make a 4x4 matrix and invert it...
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
|
I bet there are some pretty good articles buried in there. I will have to dig through since I do have a keen interest in matrices and linear algebra
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Yeah, as far as I can tell there are three main problems in the world:
- we have too many keen interests;
- there are a huge number of articles around;
- there are way too many people not searching but just asking.
|
|
|
|
|
Luc Pattyn wrote: we have too many keen interests
That's okay to an extent, but it can make things not very interesting sometimes.
Luc Pattyn wrote: there are a huge number of articles around;
Yes, and it does pose as a challenge weeding out the good from the bad. A favorite phrase from my Master's Thesis chairman, YAGNI (You Ain't Aren't Gonna Need It).
Luc Pattyn wrote: there are way too many people not searching but just asking
Yes, search first, can't find it, then ask
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Luc Pattyn wrote: we have too many keen interests;
Exactly, But the Peoples should think of it and use it.
Luc Pattyn wrote: there are a huge number of articles around;
Well Said, Because of the Pressure they are not able to read those articles.
Luc Pattyn wrote: there are way too many people not searching but just asking.
Exactly said Luc, before posting the code the guys should search it in google and after wards he could not find this means we can help you.
there are lot of peoples asking how to do without knowing the simple concepts.
That depends upon on his own interest only.
then only the programmer can sine in his life.
SSK.
|
|
|
|
|
How can i develop a traffic monitoring system. Please help me with the codes.
|
|
|
|
|
The best help I can give you (and the only help at this point) is to go some research on Google for what you're looking for, then start writing the application, then (and only then) if you run into problems come back here, give a description of the problem (along with the code thats causing the problem) then maybe someone will help you. To come here and say something like "help me with the codes" is going to get you ignored, we aren't here to do your work/homework assignments for you.
"Okay, I give up: which is NOT a real programming language????"
Michael Bergman
|
|
|
|
|
Welcoem to CP. Being a new Member here we would like to tell onething.
Before posting your query here you must get it from our Best Friend what for you are looking.
And here we are to help you if you got any problem in your application.
So please post the query accordingly.
SSK.
|
|
|
|
|
Dude, how on earth do you expect everyone to know what 'our Best Friend' means ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
There are two possibilities here
1 - you're the best they could find to impliment such a system in a third world country
2 - this is your homework
I'm betting on #2. We don't provide full solutions, homework or otherwise. We look at people's code, and provide advice. Right now, we don't even know exactly what your assignment requires, and even if we did, we would not do it for you, when you've obviously done nothing yourself.
Write some code, come back and ask us when you're stuck on something more fine grained than the whole project.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
*grin* good to be back.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: I'm betting on #2.
I would have to say. In a database course our project years ago was a driving school database/app. It was okay, quickly learned how to normalize databases :->
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Jshuwa wrote: Please help me with the codes.
Nope, I don't have the time and you don't have the money to pay me.
Jshuwa wrote: How can i develop a traffic monitoring system.
Start by doing requirements gathering, draw fancy-schmancy UML diagrams, etc. Then, starting coding away
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|