473,839 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

progrm to find a substring in a string

Hi all,Could anybody tell me the most efficient method to find a substr
in a string.

Mar 22 '06
29 51759
Al Balmer wrote:
"Rod Pemberton"

.... snip ...

You help the guy but then insult him?


Count the quote marks.


--

+-------------------+ .:\:\:/:/:.
| PLEASE DO NOT F :.:\:\:/:/:.:
| FEED THE TROLLS | :=.' - - '.=:
| | '=(\ 9 9 /)='
| Thank you, | ( (_) )
| Management | /`-vvv-'\
+-------------------+ / \
| | @@@ / /|,,,,,|\ \
| | @@@ /_// /^\ \\_\
@x@@x@ | | |/ WW( ( ) )WW
\||||/ | | \| __\,,\ /,,/__
\||/ | | | jgs (______Y______)
/\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
=============== =============== =============== =============== ==

fix (vb.): 1. to paper over, obscure, hide from public view; 2.
to work around, in a way that produces unintended consequences
that are worse than the original problem. Usage: "Windows ME
fixes many of the shortcomings of Windows 98 SE". - Hutchison
Mar 23 '06 #21
Martin Ambuhl wrote:

[etc.]
So, tell us: are you a troll or just a very, very bad programmer?


Son: "Dad, I'm a very, very bad programmer".
Dad: "No you're not, Son. Just stick with it."
Son: "Dad ... I've been thinking of making a post to CLC in the hopes
that it will make me a better programmer, but I'm a bit afraid."
Dad: "Afraid of what Son?"
Son: "Afraid that they'll call me a Troll."
Dad: "Don't worry Son. No one would ever do that."
Son: "Thanks Dad!"

....
Five agonizing days later
....

Dad: "So, Son, did you ever post to CLC?"
Son: "Yes Dad. I ... I ... I ... I did. :("
Dad: "What did they say, Son?"
Son" "That I'm a Troll."
Dad: "Sorry to hear that, Son."

....
One day later
....

Dad: "Did I mention to you that Mommy and I are getting a divorce?"
Son: "No Dad. Maybe next time I'll know better and choose C# for a
programming language."

--
jay
Mar 23 '06 #22

jaysome wrote:
Martin Ambuhl wrote:

[etc.]
So, tell us: are you a troll or just a very, very bad programmer?


Son: "Dad, I'm a very, very bad programmer".


I think you're missing the point here. The code Martin criticised was
offered as /help/ to the OP. That's almost the same as throwing a brass
ring to a drowning man. Irresponsible at best, criminal at worst. In
c.l.c terms, attempt at trolling is probably somewhere between the two.

--
BR, Vladimir

Mar 23 '06 #23
"Vladimir S. Oka" <no****@btopenw orld.com> writes:
jaysome wrote:
Martin Ambuhl wrote:

[etc.]
> So, tell us: are you a troll or just a very, very bad programmer?


Son: "Dad, I'm a very, very bad programmer".


I think you're missing the point here. The code Martin criticised was
offered as /help/ to the OP. That's almost the same as throwing a brass
ring to a drowning man. Irresponsible at best, criminal at worst. In
c.l.c terms, attempt at trolling is probably somewhere between the two.


And the code contained so many fundamental errors, of kinds that have
been pointed out here again and again and again (void main(), gets(),
<conio.h>), as well as posting errors ("U" for "You", no context),
that it wasn't entirely unreasonable to assume that it might have been
deliberate. At the very least, the poster was trying to offer advice
without having read, or at least paid any attention to, this
newsgroup.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 23 '06 #24
jaysome wrote:
Martin Ambuhl wrote:
[etc.]
So, tell us: are you a troll or just a very, very bad programmer?


Son: "Dad, I'm a very, very bad programmer".
Dad: "No you're not, Son. Just stick with it."
Son: "Dad ... I've been thinking of making a post to CLC in the hopes
that it will make me a better programmer, but I'm a bit afraid."
Dad: "Afraid of what Son?"
Son: "Afraid that they'll call me a Troll."

<snip>

Although hinting that someone may be a troll based on a single posting
is a bit harsh, "binny's" code was shot full of unportable constructs
and terrible formatting, so Martin Ambuhl's reply is entirely
inappropriate.

On the other hand, hinting, (as you do in your post), that *all*
regulars in c.l.c are ready to label posters as trolls at the drop of a
hat, just hastens your progress into the killfile.

Mar 23 '06 #25

santosh wrote:
jaysome wrote:
Martin Ambuhl wrote:
[etc.]
So, tell us: are you a troll or just a very, very bad programmer?


Son: "Dad, I'm a very, very bad programmer".
Dad: "No you're not, Son. Just stick with it."
Son: "Dad ... I've been thinking of making a post to CLC in the hopes
that it will make me a better programmer, but I'm a bit afraid."
Dad: "Afraid of what Son?"
Son: "Afraid that they'll call me a Troll."

<snip>

Although hinting that someone may be a troll based on a single posting
is a bit harsh, "binny's" code was shot full of unportable constructs
and terrible formatting, so Martin Ambuhl's reply is entirely inappropriate.


^n't

Mar 23 '06 #26
santosh wrote:
Although hinting that someone may be a troll based on a single posting
is a bit harsh, "binny's" code was shot full of unportable constructs
and terrible formatting, so Martin Ambuhl's reply is entirely
inappropriate.


I admit being confused by this post. Everything before the final clause
suggests that it should have been "so Martin Ambuhl's reply is entirely
appropriate" or the weaker "so Martin Ambuhl's reply is not entirely
inappropriate." Could you explain binny's being "shot full of
unportable constructs and terrible formatting" (as well as outright
errors) makes my reply inappropriate?
Mar 23 '06 #27
Martin Ambuhl wrote:
santosh wrote:
Although hinting that someone may be a troll based on a single posting
is a bit harsh, "binny's" code was shot full of unportable constructs
and terrible formatting, so Martin Ambuhl's reply is entirely
inappropriate.


I admit being confused by this post. Everything before the final clause
suggests that it should have been "so Martin Ambuhl's reply is entirely
appropriate" or the weaker "so Martin Ambuhl's reply is not entirely
inappropriate." Could you explain binny's being "shot full of
unportable constructs and terrible formatting" (as well as outright
errors) makes my reply inappropriate?


I assume that you can't see my follow-up post yet? It was a silly typo
that happened at the worst possible place! I meant:

....so Martin Ambuhl's reply isn't entirely inappropriate.

:)

Mar 23 '06 #28
jaysome wrote:
Martin Ambuhl wrote:

[etc.]
So, tell us: are you a troll or just a very, very bad programmer?


Son: "Dad, I'm a very, very bad programmer".


[blither snipped]
You really aren't all that smart, are you?


Brian
Mar 23 '06 #29
dumpy_iitr
1 New Member
int s1Index = 0,s2Index = 0,templastIndex = -1,lastIndex = -1;
BOOL possibility = FALSE,found =FALSE;
while(s1[s1Index]!='\0')
{
if(!possibility && s1[s1Index] == s2[0])
{
templastIndex = s1Index;
possibility = TRUE;
s1Index++; s2Index++;
}
else if((s1[s1Index]!='\0' && s2[s2Index]!='\0') && (s1[s1Index] == s2[s2Index]) )
{
s1Index++; s2Index++;
}
else if(s2[s2Index]=='\0')
{
found = TRUE;
lastIndex = templastIndex;
s1Index++; s2Index = 0;
possibility = FALSE;
}
else
{
s1Index++; s2Index = 0;
possibility = FALSE;
}
}//end while
Apr 21 '06 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
8963
by: Jozef Jarosciak | last post by:
Quickest way to find the string in 1 dimensional string array! I have a queue 1 dimensional array of strings called 'queue' and I need a fast way to search it. Once there is match, I don't need to search any longer. Currently I am using this code. But I think it's too slow, because it runs through whole dimension. I know this is trivial question, but is there any way to stop this loop, or better way to search? I mean - FASTER?
2
1827
by: Robin Tucker | last post by:
Hiya, Regular expressions always do my gnads in - can anyone cook up a reg expression to find all string literals in my code? I would like to put them into a resource file for future translation :) Thanks,
2
1763
by: Gaijinco | last post by:
I was trying a function that read an string (which previously had attached two special characters & for the beginning of the word and # for the end of the word) and if it was "<word>ize" it changed into "change into <word>". I did this function: bool Ize(string& s) { bool is=false; string eval="ize"; int end=s.find('#');
3
1703
by: Austin Varghese | last post by:
How can i find a string from a file and hilight it? somebody pls help me
1
2472
by: sai14 | last post by:
Hi all, i would like to know if it is possible find particular string in a text file using vc++? please do let me know how to write the syntax Thanks
2
1311
by: Pradeep Arkasali | last post by:
directory is /v_dialer in that i have to find the string v_dialer in all the files as well as subdirectories, here for some of the files i don't have ownership,how can i use ownership in this context. reply ASAP drwxrwxr-x 11 ccvob01 ccgrp01 236 Aug 13 2005 3rdparty -r-xr-xr-x 1 ccvob01 ccgrp01 4797 Mar 14 13:56 Make.system -r-xr-xr-x 1 ccvob01 ccgrp01 8488 Feb 17 2001 Make.targets -r-xr-xr-x 1 ccvob01 ...
5
8356
by: neeludhiman | last post by:
Hi All, Can someone please help me with the code in C / C++ to find a string in an input text file and replace it with another string in output text file. The catch is that white spaces in the input file should be retained in output file. And, if possible we should be able to replace multiple search strings with multiple replace strings. e.g; srch1, srch2, srch3 in in.txt should be replaced by rplc1, rplc2, rplc3 in out.txt Thanks.
2
2343
by: powerfulperl | last post by:
I want to locate a string 'Local=IN' from a file and I am sure that this string is located within 100 lines(assumption) from the beginning of the file out of 5000 lines. The 100th line start with the word '--Begin'. So in order to locate the string from only 100 line, I think copying all the file content into any array is not a good idea. I want the grep command to exist in the script. I have the following code. I need this to be modified...
3
1405
by: Rob S | last post by:
Hi, I am not sure where I am going wrong with this code. It seems to work fine for a small text file but when I use files larger than 100MB it does not give me an accurate count. The program is pretty simple. It should return the number of occurences of a substring from within a text file. I look for a match to the first character of the substring and if found then my code should test to see if the whole substring exists. I have run...
0
9854
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9696
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10903
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10584
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7015
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5681
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.