Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7011117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:05:11+00:00 2026-05-27T22:05:11+00:00

I have this large XML file. There is a field that I want to

  • 0

I have this large XML file. There is a field that I want to split a field by space.

So I do the following to save the splitted data into a & b:

components = a.split(' ')
a = components[0]
b = components[1]

However some are splitted correctly, but some are not (when they all contain spaces). For example when I try to split 'Maria Canada' it does not split by space.

I am not sure why. If I open the file in Vim and copy those particular wrong text, I can split them correctly in Ruby interactive shell:

'Maria (Canada)'.split(' ')
 => ["Maria","(Canada)"]

UPDATE

Ok the reason is NBSP. I printed out those lines which doesn’t split in the console by raising errors. I copied the text and pasted in irb. These copied text can’t be splitted in irb either, nor can I strip that space.

>> ' '.strip
=> " "

I then run ord and found out that the space is a NBSP character (its code is 160):

>> ' '.ord
=> 160

So the xml file contains both space and NBSP characters. I think Vim auto converts NBSP to spaces, and that’s why when I tried to copy it from vim it is not NBSP anymore.

Now I just need to figure out how to deal with NBSP.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:05:11+00:00Added an answer on May 27, 2026 at 10:05 pm

    You should split on all whitespaces, including the non-ASCII ones:

    a, b = str.split(/[[:space:]]/)
    

    I’m assuming you are using Ruby 1.9+ and that your str has the right encoding (e.g. utf-8). As explained in the regex reference, \s matches only ASCII spaces, while [[:space:]] will match all unicode spaces (same for \d vs [[:digit:]], etc…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large xml file that looks like this: 20120124 07:30:15.301, saving to
I have a large XML file (3000+ nodes) that I want to represent in
I have a large nested vector that look like this: import Data.Vector let x
I have a very large XML file that I need to parse so I
I have several fairly large XML files that represent data exported from a system
I have a function, that gets a large XML file, then parses it, and
I have a large XML file (~18MB). Apparently there is a tag somewhere in
I have a large amount of data that I am pulling from an xml
I have a large XML, looking like this: <gender>M</gender> <last-name>*</last-name> <profession>2165dda2-dc59-41af-acb5-06d8914c4841</profession> <first-name>*</first-name> <mail-confirmation>1</mail-confirmation> <fax-confirmation>1</fax-confirmation>
I have this relatively large numerical application code that may run for a few

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.