![]() |
| | #1 |
| Registered User Join Date: Apr 2009
Posts: 13
| If I have this string 'Hello+Julie+I-was-here', how do I get this expecting result with C programming? 'Hello+Julie' 'I-was-here' Another example, String: 'I+am+really+tired+mememe-is-now-at-home' Result: 'I+am+really+tired' 'mememe-is-now-at-home' As noticed, I will want to break up my string into 2. Based on the last + sign from the back in the string, I will separate the string into 2 separate strings. How am I suppose to do this? Last edited by JuzMe; 04-18-2009 at 03:49 AM. |
| JuzMe is offline | |
| | #2 |
| Registered User Join Date: Oct 2008
Posts: 452
| Erm... What about looping through the string, mark the last + you found, replace it by a null character, and add one to get the second string..? You could copy the string, which you have to if it's a constant string, but if not it's too much overhead. Although, 99% of the cases the string should really be constant in this case . |
| EVOEx is offline | |
| | #3 | |
| Registered User Join Date: Apr 2009
Posts: 13
| Quote:
| |
| JuzMe is offline | |
| | #4 |
| Registered User Join Date: Sep 2006
Posts: 2,512
| Before you can learn any trick riding skills, you have learn how to actually ride the horse, a little. This requires using a string (a char array[]), and working with an index with that array - not the only way but probably the simplest. Learn about using a char array and an index, and how to print a string, and a newline. Then your answer will be made clear to you, and you will have learned something valuable in the process. |
| Adak is offline | |
| | #5 | |
| Registered User Join Date: Apr 2009
Posts: 13
| Quote:
| |
| JuzMe is offline | |
| | #6 |
| Registered User Join Date: Sep 2006
Posts: 2,512
| A good place to start is Ivor Horton's book - "Beginning C". Covers all the basics, in a down to earth style. Also, has several examples of great problem solving, using the basics discussed in the previous chapters. K&R "The C Programming Language" is excellent, but not for beginners. There are many C tutorials on-line, but you'll have to Google them up. |
| Adak is offline | |
| | #7 |
| Registered User Join Date: Apr 2009
Posts: 13
| Actually, it is not say I do not want to learn. But I am stuck and rushing to meet the dateline so I do not have time to look for these books.... Is ok.... I will look at other places. |
| JuzMe is offline | |
| | #8 |
| Registered User Join Date: Apr 2009
Posts: 13
| I am really sorry..... I am really desperate for help... Can anyone guide me what I should really do? I don't even know how to begin. |
| JuzMe is offline | |
| | #9 |
| CSharpener Join Date: Oct 2006
Posts: 5,242
| use strrchr to find the last '+' character and then replace it with 0 (like strtok does) or strncpy first part of the string to the side...
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. |
| vart is offline | |
| | #10 | |
| Registered User Join Date: Apr 2009
Posts: 13
| Quote:
Thanks for your help. But I need your help further. For this string: String: 'I+am+really+tired+mememe-is-now-at-home' With strrchr, I was able to get 'mememe-is-now-at-home'. But the problem is how do I get I+am+really+tired? Does anyone knows about it? | |
| JuzMe is offline | |
| | #11 |
| DESTINY Join Date: Jul 2008 Location: in front of my computer
Posts: 656
| show the code u have made till now. |
| BEN10 is offline | |
| | #12 |
| Making mistakes Join Date: Dec 2008
Posts: 347
| that's easy. Like vart said: Code: char *end = strrchr(string, '+'); /* Get the last occurrence of '+' */ end[0] = '\0'; /* Replace it with a nul byte */ end++; /* Skip it */ |
| Brafil is offline | |
| | #13 |
| Registered User Join Date: Apr 2009
Posts: 13
| Thank you. It works |
| JuzMe is offline | |
![]() |
| Tags |
| seperate, string, word |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| find a string based on the location of another string | rlilley | C Programming | 3 | 02-19-2009 12:29 PM |
| OOP Question DB Access Wrapper Classes | digioz | C# Programming | 2 | 09-07-2008 04:30 PM |
| String Class | BKurosawa | C++ Programming | 117 | 08-09-2007 01:02 AM |
| RicBot | John_ | C++ Programming | 8 | 06-13-2006 06:52 PM |
| can anyone see anything wrong with this code | occ0708 | C++ Programming | 6 | 12-07-2004 12:47 PM |