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

  • Home
  • SEARCH
  • 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 546057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:49:37+00:00 2026-05-13T10:49:37+00:00

I have a comma delimited text file. The 5th field on each line contains

  • 0

I have a comma delimited text file. The 5th field on each line contains the name and address information. The name is separated from the street information by a ‘¬’ character. The same character also separates the city|state|zip. A sample field would be:
“¬BOL¬MICKEY M MOUSE¬123 TOMORROW LANE¬ORLANDO FL 12345-6789¬¬¬¬EOL¬”

I need to separate the name into parts and the city|state|zip into parts. However, the name may or may not have a middle initial so:

m = l[4].split(“¬”)
firstName, mi, lastName = m[2].split()

won’t work if there is no middle initial. Also, the name of the city may or may not have spaces so:

city, state, zipCode = m[4].split()

won’t work if the city is ‘San Antonio’ or ‘Rio de Janeiro’ for instance.

Bottom line, how do I parse sections of a field where the section is not always in the same format?

  • 1 1 Answer
  • 1 View
  • 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-13T10:49:37+00:00Added an answer on May 13, 2026 at 10:49 am

    In your examples it seems that you can in both cases solve the problem by getting the ‘first fields’, the ‘last fields’ and ‘everything in between’:

    m = line.split("¬")[2].split()
    firstname = m[0]
    surname = m[-1]
    initials = m[1:-1] # Maybe just keep this as a list?
    

    And:

    m = line.split("¬")[4].split()
    city = ' '.join(m[:-2])
    state = m[-2]
    zipCode = m[-1]
    

    In general you can handle a single field containing spaces by getting the ‘fixed’ fields from both the start and the end and whatever is left over is the field that can contain spaces.. As soon as you have two fields containing spaces in the same column, there’s nothing you can do. It’s ambiguously defined.

    With the data format you have, you may have some problems if there are people with first or last names containing spaces such as Robert Van de Graff. This can be solved if you have an initial by looking for words containing only one letter such as: Robert J. Van de Graaff and using those to define where the first and last names start and end. But in general you may have problems.

    Also there’s an internationalization issue hidden here: not everyone writes their ‘first name’ first – sometimes they write their family name first.

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

Sidebar

Related Questions

I have a text file that is in a comma separated format, delimited by
I have a class that parses in data from a comma delimited text file.
Possible Duplicate: Reading csv file I have a comma delimited file: Some Text, More
I have a text file (its comma delimited with some fields wrapped around in
If I have a text file, which say is comma delimited and has several
I have a text file containing 5-line chunks of tab-delimited lines: 1 \t DESCRIPTION
I have a file that is comma delimited Text File: some_key_1, Translation 1 some_key_2,
I have a comma delimited file with as a text qualifier. Currently I have
I have a text file containing ~300k rows. Each row has a varying number
I have a column in my table called tags. It has comma delimited text

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.