• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

Need Split(' ') to work with one OR MORE spaces

I have a string that's space delimited. But when there are two or more spaces between valid pieces of data, it's not working.

I need one, two, three or more spaces to be delimeters.

What call to Split() would handle this?

Thanks,
newbieweb
0
newbieweb
Asked:
newbieweb
  • 2
1 Solution
 
Ron MalmsteadInformation Services ManagerCommented:
The best way to handle that is to do a .replace("  "," ")... before the split, that way you are counting double spaces as a single delimiter.  You can do this without affecting the original string.
0
 
Ron MalmsteadInformation Services ManagerCommented:
In  vb.net, it might look something like this...
dim strtempvar as string = (stryourstring.tostring.replace("  "," ").tostring).tostring.split(" ").GetValue(0).tostring
0
 
newbiewebAuthor Commented:
Yes, but then I need to loop to be sure al double spaces are replaced. Right?
0
 
magicdlfCommented:
           str.Split(new char{' '}, StringSplitOptions.RemoveEmptyEntries);
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now