dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: How would I split this complex string into an String array?

  1. #1
    Join Date
    Oct 2018
    Posts
    1

    How would I split this complex string into an String array?

    I have a text file that I have to read and there was this complex string that I have to store into a String array. I have read about regex, but would really like if someone could help me understand how a complex string such as this could be broken into tokens and stored in an array

    String sentence = "I said, "Mr. Jonesí golf 'golden' clubs were broken"."

    Maybe using

    scanner.next()

    And then removing each of those punctuation marks, but how would I end up doing that?

    The final array i'd like an array that looks like the

    > Array words[] = {"I", "said", "Mr", "Jones", "golf", "golden", "clubs", "were", "broken"};

    Any help is appreciated, thank you!

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,808

    Re: How would I split this complex string into an String array?

    Use string split with a space as the delimiter to put the items into an array. Then walk the array and remove punctuation from each array elemnt.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)