Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,208,110 members, 8,001,538 topics. Date: Wednesday, 13 November 2024 at 11:58 AM |
Nairaland Forum / Science/Technology / Programming / Contest[closed] : Program A Function to find if a phrase. is in a string (4061 Views)
Php Function To Generate A Random Expression / User Defined Function To Validate Regular Expression In Javascript / I Can Program A Html Css Javascript Website For 1k (2) (3) (4)
Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 12:11am On Aug 01, 2017 |
just a simple but powerful function to improve our coding skills beginners onlys so the function will do the following when given a two parameters the first will be a word and second will be a sentence it should be able to detect that the word is in the sentence example function find("boy","obi is a boy" { code........ return 0 or 1 } the function will return 0 or 1 0 if word not found in the sentence 1 if word is found in the sentence contest is closing on 3rd of this month Note : you are not allowed to use any inbuilt library or functions just from scratch code every thing some time similar to str.find() in python any language is welcomed but c and c ++ Will be more interesting pros are not welcomed just New coders SINCE WE DO NOT HAVE A WINNER I WILL LIKE TO Honor THIS GREAT PROGRAMMERS 1.justanALIAS (golang) 2.jidez007 (c++) please drop your numbers for a little appreciation SOLUTION IN C language
|
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 12:13am On Aug 01, 2017 |
3days for the contest to run |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Nobody: 1:05am On Aug 01, 2017 |
And of course I will be umpire. . . |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Desyner: 1:14am On Aug 01, 2017 |
Clarify please. Custom functions that don't call library function? |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Jaddo19(m): 1:19am On Aug 01, 2017 |
I Really Dont Understand D Question Fully, Can U Explain Better Pls |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 6:42am On Aug 01, 2017 |
Jaddo19: I hope you understand it now |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 6:43am On Aug 01, 2017 |
Desyner: just a custom function but no library or inbuilt function |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Welete(m): 7:46am On Aug 01, 2017 |
#python 3.x def wordsearch(x, sent): for x in sent: return 1 break else: return 0 x = input('word: ') sent = input('sentence: ') wordsearch(x, sent) |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Welete(m): 7:51am On Aug 01, 2017 |
Welete: nairaland is messing with my indentation.. |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Jaddo19(m): 8:22am On Aug 01, 2017 |
Using Php . . <?Php If (strpos("is This What You Want","What"){ Echo true; }else{ Echo (int)false; } ?> |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 8:28am On Aug 01, 2017 |
Jaddo19: great but no inbuilt function or library and fancy operator https://msdn.microsoft.com/en-us/library/2hxce09y(v=vs.90).aspx?_e_pi_=7%2CPAGE_ID10%2C1207831521 |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 8:29am On Aug 01, 2017 |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 8:30am On Aug 01, 2017 |
Welete: in operator a membership operator only in python I consider it inbuilt function |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 8:33am On Aug 01, 2017 |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Nobody: 9:41am On Aug 01, 2017 |
package main import( "fmt" "strings" ) func main(){ if check("justanALIAS", "justan") == 1 { fmt.Println("success") }else { fmt.Println("failure") } func check(main string, sub string) int { if strings.Contains(main, sub){ return 1 }else { return 0 } } |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Nobody: 9:43am On Aug 01, 2017 |
justanALIAS:Golang |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 1:46pm On Aug 01, 2017 |
golang hard ooo |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Nobody: 2:02pm On Aug 01, 2017 |
silento:not true oo |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by mustaphagreens(m): 2:18pm On Aug 01, 2017 |
Python 3.5 Check the attached image 1 Like
|
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 6:46pm On Aug 01, 2017 |
python user without the help of in operator rewrite you code |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Nobody: 6:50pm On Aug 01, 2017 |
^^^Na wa o! |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Olyboy16(m): 10:43pm On Aug 01, 2017 |
in Kotlin
|
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Nobody: 10:59pm On Aug 01, 2017 |
^^^Yah! |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 8:51am On Aug 02, 2017 |
mustaphagreens: wow that's great nice indentation in your code But can you rewrite the code so that if Len() will not be there the essence of this contest is to make you understand what happen beneath the standard libraries and function anyway you will do great things in python keep on trying you got the heart of a coded indeed |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Nobody: 10:07am On Aug 02, 2017 |
Sorry just seeing this, I will post mine the goal is no inbuilt function and yet people still using contains and strpos this is why Nigerians fail algorithm test, even the interview we conducted we spelt it out loud and yet still the same thing. |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 10:39am On Aug 02, 2017 |
pcguru1: nawa the tire me ooo |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Nobody: 12:29pm On Aug 02, 2017 |
package main import ( "fmt" ) // i made my own len() method func length(dstring string) int { var counter int for range dstring { counter++ } return counter } func main() { mainstr := "i am a bon boi" substr := "boi" fmt.Println(check(mainstr, substr)) } func check(mainstr string, substr string) int { var status bool = false for i, _ := range mainstr { if mainstr[i] == substr[0] { last := length(substr) di := i + last if substr == mainstr[i:di] { status = true } else { continue } } } if status { return 1 } else { return 0 } } |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 1:12pm On Aug 02, 2017 |
justanALIAS:range is inbuilt operator in golang can you scrap it |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Nobody: 2:22pm On Aug 02, 2017 |
silento:I dont think so but i will try. By the way, the above code is buggy; see d fixed version: package main import ( "fmt" ) func length(dstring string) int { // i made my own len() method var counter int for range dstring { counter++ } return counter } func main() { mainstr := "i am a bon boni" substr := "i am" fmt.Println(check(mainstr, substr)) } func check(mainstr string, substr string) int{ var status bool = false for i, _ := range mainstr { if mainstr[i] == substr[0] { if length(mainstr[i:]) >= length(substr) { last := len(substr) di := i + last var rangeof string = mainstr[i:di] if substr == rangeof{ status = true } else { continue } } else { continue } } } if status { return 1 } else { return 0 } } |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 3:03pm On Aug 02, 2017 |
justanALIAS: ok |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by CryptoCoinr(f): 4:15pm On Aug 02, 2017 |
I'm more of an amateur than a newbie (sort of) but it took longer than I expected, and more iterations than I anticipated (still have them in Sublime Text), but I finally did it. This is in JavaScript:
You can test it yourself with your browser (Chrome; any browser really but the shortcut is for Chrome) if you're using a PC. - Press Ctrl + Shift + J in any open tab - Copy and Paste the above code into the console and hit the Return/Enter key - Type find("whatever word you want to find", "whatever sentence you want the word to be found in" ) into the console and hit the Return/Enter key. |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by CryptoCoinr(f): 4:56pm On Aug 02, 2017 |
OK. Here are the shortcuts for all (most) browsers to open the console: Chrome and Firefox - Ctrl + Shift + J Edge and IE - F12, then select "Console" |
How Do I Pay For Apps On Google Play Store / Programming Languages Inventors / User Interface Design For The Beginning Web Programmmer
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 41 |