Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    0
    ReputationRep:
    So basically, or teacher gave us a task to do a few weeks ago on visual basic. However, we habe now moved on to our coursework and have forgotten about our task. But the task is still bugging me and i would like if someone wrote it amd explained it. No one in the class has complete it.

    Task:
    Develop a program that identifies individual words in a sentence, stores these in a list and replaces each word in the original sentence with the position of that word in the list.

    For example, the sentence:
    Ask not whay your country can do for you ask what you can do for your country
    Contains the words: ask, not, whay, your, country, can, do, for, ypu

    The sentence can be recreated from the positions of these words in this list using the sequence 1,2,3,4,5,6,7,8,9,1,3,9,6,7,8,4, 5

    Save the list of words and the positions of these words in the sentence as seperate files or as a single file.

    Basically:
    Identify the individual words in a sentence and store them in a list
    Create a list of positions for words in that list
    Save these lists as a single file or as separate file

    Thanks in advance to whoever can solve this task
    Offline

    12
    ReputationRep:
    Read each word in the sentence and copy it to a file (after checking is inst already on there) each time you do this add a the word to an array. e.g. word(1) =ask , word(2)=not etc. when it reaches a repeat word, it would just skip it
    Then read the original sentence again comparing it to the words in the array, if a match is found, you can just add the position of the word in the array to an output string.

    I'm second year Alevel computing student and think this would work, but there's probs a more efficient way to do it...sorry if I've typed it up poorly.
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by Aydin7)
    Read each word in the sentence and copy it to a file (after checking is inst already on there) each time you do this add a the word to an array. e.g. word(1) =ask , word(2)=not etc. when it reaches a repeat word, it would just skip it
    Then read the original sentence again comparing it to the words in the array, if a match is found, you can just add the position of the word in the array to an output string.

    I'm second year Alevel computing student and think this would work, but there's probs a more efficient way to do it...sorry if I've typed it up poorly.

    See, this is the second part of the task... I have the first array etc. This is basically the code for the first task which was to find one specific word in the sentence and to display it or an error message will appear if the word isnt there
    Dim words() = myString.Split({". ", ", ", " "},StringSplitOptions.None)

    Dim indexes = From i In Enumerable.Range(0, words.Length) Where String.Equals(words(i), "programs", StringComparison.CurrentCultureI gnoreCase)

    Select i For Each i In indexes
    Console.WriteLine(i)
    Next

    This is the basic code for that without the variable and if statement. How would this array be used with the new array to store the positionSorry if that makes no sense
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Has a teacher ever helped you cheat?
    Help with your A-levels

    All the essentials

    The adventure begins mug

    Student life: what to expect

    What it's really like going to uni

    Rosette

    Essay expert

    Learn to write like a pro with our ultimate essay guide.

    Uni match

    Uni match

    Our tool will help you find the perfect course for you

    Study planner

    Create a study plan

    Get your head around what you need to do and when with the study planner tool.

    Study planner

    Resources by subject

    Everything from mind maps to class notes.

    Hands typing

    Degrees without fees

    Discover more about degree-level apprenticeships.

    A student doing homework

    Study tips from A* students

    Students who got top grades in their A-levels share their secrets

    Study help links and info

    Can you help? Study help unanswered threadsRules and posting guidelines

    Sponsored content:

    HEAR

    HEAR

    Find out how a Higher Education Achievement Report can help you prove your achievements.

    Groups associated with this forum:

    View associated groups
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Write a reply...
    Reply
    Hide
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.