473,385 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

extract information from a string with a lot of spaces

ok I have this string and other similar( ull find them in the attachment)

"BRUNEI BANDAR SERI BEGAWAN 5770 343653"

I need to extract BRUNEI, BANDAR SERI BEGAWAN, 5770 and 343653
but i cant find a way to do it that work for all my string that i have..
Can someone help me on that plz..
thx
Attached Files
File Type: txt pays_h10.txt (14.5 KB, 422 views)
Feb 22 '10 #1
5 1832
tlhintoq
3,525 Expert 2GB
This is very obviously a work for hire project that you are asking others to code for you.

Do you really think it is right? You took on a paying contract to parse through a file of names and addresses - and now you want the volunteers here to tell you how to do it, for free.

"I can't find a way", implies that you have at least TRIED to find a way. Please tell us what you have tried. Please show us the code you have tried so far and what errors it is giving you.
Feb 22 '10 #2
Yeah.. sorry, it's the first time that i'm writing on a page like that...
ok that's what i tried, it worked for quite all of them and i had a problem with only one..
it's one of my contrustor...
so while im searching in my string i'm looking first, if it's not a space then i'm putting in the good variable, then after, if the caracter it's a space, i'm gonna look if the caractor next to it (i+1) it,s a space to, then after if the caractor at i+2 is different then a space, so it's a different word... then i'll change variable with indice...
then if it's a but the space is include in the word like "BUENOS AIRES" ill right it down in my variable... but the problem then, it's for BRUNEI between BANDAR SERI BEGAWAN and 5770 there's only one space so BANDAR SERI BEGAWAN 5770 are only one variable... so there's where i'm stuck... i cant find a way to resolve the problem.

Expand|Select|Wrap|Line Numbers
  1. public pays(string extrInfo)
  2.         {
  3.             int indice = 1;
  4.             continent = extrInfo[0];
  5.             for (int i = 1; i < extrInfo.Length; i++)
  6.             {
  7.                  if (!(extrInfo[i] == ' '))
  8.                 {
  9.                     switch (indice)
  10.                     {
  11.                         case 1:
  12.                             paysnom = paysnom + extrInfo[i];
  13.                             break;
  14.                         case 2:
  15.                             capital = capital + extrInfo[i];
  16.                             break;
  17.                         case 3:
  18.                             supercifie = supercifie + extrInfo[i];
  19.                             break;
  20.                         case 4:
  21.                             population = population + extrInfo[i];
  22.                             break;
  23.                     }
  24.                 if (extrInfo[i] == ' ' && (extrInfo[i + 1] == ' ') && !(extrInfo[i + 2] == ' '))
  25.                 {
  26.                     indice++;
  27.                 }
  28.                 else if (extrInfo[i] == ' ' && !(extrInfo[i + 1] == ' ') && !(extrInfo[i - 1] == ' '))
  29.                 {
  30.                     switch (indice)
  31.                     {
  32.                         case 1:
  33.                             paysnom = paysnom + extrInfo[i];
  34.                             break;
  35.                         case 2:
  36.                             capital = capital + extrInfo[i];
  37.                             break;
  38.                         case 3:
  39.                             supercifie = supercifie + extrInfo[i];
  40.                             break;
  41.                         case 4:
  42.                             population = population + extrInfo[i];
  43.                             break;
  44.                     }
  45.                 }
  46.  
  47.                 }
  48.             }
  49.         }
Feb 22 '10 #3
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Feb 22 '10 #4
tlhintoq
3,525 Expert 2GB
Read up on MSDN regarding the string.split method.
You give it a single string, such as the line you are trying to parse, along with the character you want to use for splitting (a space in your example) and it will return a string array of all the little sub strings.

Expand|Select|Wrap|Line Numbers
  1. string Source = "BRUNEI BANDAR SERI BEGAWAN 5770 343653";
  2. string[] SplitUp = string.split(Source, ' ');
  3. string paysnom = SplitUp[0];
  4. string capital = SplitUp[1]
  5. // and so on
  6.  
Feb 22 '10 #5
Thx!
I found an other way easier than everything that i saw
each variable have a limited number of space to use, it cant pass over it
so with the length of my string i did a substring then a trimend! i got all what i needed!
Feb 22 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: rdraider | last post by:
Is there a function that will extract part of a string when the data you want does not occur in a specific position? Field "REF" is varchar(80) and contains an email subject line and the email...
3
by: zek2005 | last post by:
Hi friends! I have a varchar field in my DB with numeric values separates by spaces. I need to extract the numbers to create an array. Example 1: 1820 1823 1825 --> need to be transform into ...
4
by: yinglcs | last post by:
Hi, how can I extract 2 integers from a string in python? for example, my source string is this: Total size: 173233 (371587) I want to extract the integer 173233 and 371587 from that...
3
by: deko | last post by:
I'm sure someone has passed this way before... I want to check to see is a domain name is contained in a string, and if one is, I want to extract it. In these strings, domains are always...
5
by: deko | last post by:
If I have random and unpredictable user agent strings containing URLs, what is the best way to extract the URL? For example, let's say the string looks like this: registered NYSE 943 <a...
1
by: caine | last post by:
I want to extract web data from a news feed page http://everling.nierchi.net/mmubulletins.php. Just want to extract necessary info between open n closing tags of <title>, <categoryand <link>....
3
by: adimangla | last post by:
Hi :-) I am creating a software that will save the present state of all the applications running on the desktop (WinXP). Can anyone point out the method to extract the filenames from the...
4
by: Alexander Vasilevsky | last post by:
How to extract email address from the letter in Outlook Express? http://www.alvas.net - Audio tools for C# and VB.Net developers
3
by: learningvbnet | last post by:
Hi, I am trying to extract zipped files using Winzip in my VB.net application and I ran into 2 stone walls. 1. How do you handle file names with spaces. See psiProcess.Arguments For...
1
by: Edwin.Madari | last post by:
from each line separate out url and request parts. split the request into key-value pairs, use urllib to unquote key-value pairs......as show below... import urllib line = "GET...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.