frankenstein - % found in the 1st input string to the...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
% 9/9/09 11:43 PM % Function Name: frankenstein % Inputs: 1. char vector - string that contains a set of words separated by % a space % 2. char vector - embedded string to find % Output: 1. char vector - string with new frankenstein word % % Function Description: % The function takes in two strings, the first of which contains the old % string, and the 2nd containing a string that may be embedded within the % first input string (e.g. 'as' is embedded in 'last'). The function % then returns a single string that is generated based on the following % criteria: % % 1) Whenever a space is detected in the 1st input string, add the % character (or space) after the space to the output word. % 2) Whenever the 2nd input string is detected within the 1st input string, % add the letter preceding the index at which the embedded string was
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % found in the 1st input string to the output word. You may assume that % only letters will precede this particular string. % 3) If an indices found from 1) and 2) are the same, simply include the % same referenced character twice. % 4) The letters specified in 1) and 2) should be assembled into the % output word in the order in which they originally appeared. % function sum = frankenstein(phrase, pattern) spaces = strfind(phrase, ' ')+1; % finding out what indices to add based on spaces embedded = strfind(phrase, pattern)-1; % finding out what indices to add based to imbedded pattern indices = sort([spaces embedded]); % putting the indices together then sorting them sum = phrase(indices);...
View Full Document

This note was uploaded on 10/22/2009 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Tech.

Ask a homework question - tutors are online