5
$\begingroup$

I have worked for two days to find a way through this problem.

I am porting my student grade records into Mathematica from spreadsheets, or sometimes from my college web sites, or sometimes from my word processor. I have many different source formats as you see, but I find I can always get the data into the format where it will paste into a word processor in one or the other format sketched in my subject line above.

I can deal with the Mathematica end of the project once the grades are in the form List["B+", "C-", "A", "B"] -- from there convert them into gpa's, points, sums, averages, whatever -- but I have not been able to operate on the data Pasted into Mathematica because the pluses and minuses are interpreted as parts of incomplete expressions, which blocks execution of string functions.

To get the data in, I need to use use the Windows Copy command, then Paste into Mathematica. The source can easily be one of the two character formats shown just below. (Or see my subject line.) But unfortunately the grades often have pluses and minuses, especially B+ or C+.

But if I paste the following example straight into List in an Input cell, it is interpreted as an incomplete expression:

List[D+, F , C-, F, A-, B, A, A- ,D-, B-, C-, B, D-, D, B, D, A+, B, D, B+, F, C-, F, C+, D-, D+, B]

The same thing happens if I paste the same information in this way:

List[D + F C - F A - B A A - D - B - C - B D - D B D A + B D B + F C - F C + D - D + B]

So I need a "container" to paste into, which will eliminate white spaces, attach any pluses or minuses to the preceding character, and interpret each letter grade as a string as here: List["B+", "C-", "A", "B"] (By the way the only letters which appear are ABCDFWI, if that permits simplification, and the only non-letters are + and -).

I feel kinda dumb asking about this, but Strings in Mathematica are so crazy I'm just not there yet.

$\endgroup$
2
  • $\begingroup$ Why not just Import the Excel file directly into Mathematica? You get an array identical to that in your spreadsheet. $\endgroup$
    – user12911
    Mar 11, 2014 at 11:48
  • $\begingroup$ Some grades are copied and pasted from a university website, also my spreadsheets are so large, with so many sheets and formulas and cells without data, that my computers all hang when I attempt the Import. This is an issue I may give to the stackExchange at some point.... $\endgroup$
    – GeofAndron
    Mar 11, 2014 at 14:55

1 Answer 1

8
$\begingroup$

If you paste your expression as a string, this should work:

s = "D+,F,C-,F,A-,B,A,A-,D-,B-,C-,B,D-,D,B,D,A+,B,D,B+,F,C-,F,C+,D-,D+,B";

StringSplit[s, ","] 

{"D+", "F", "C-", "F", "A-", "B", "A", "A-", "D-", "B-", "C-", "B", "D-", "D", "B", "D", "A+", "B", "D", "B+", "F", "C-", "F", "C+", "D-", "D+", "B"}

$\endgroup$
1
  • $\begingroup$ This worked. Thanks. My mistake was thinking that String[A+C-DDF,A] would CREATE a string out of the sequence, create "A+C-DDF,A". I now see String doesn't do this. String is not like Plus, or Plot, it is like Symbol. It's just a Head. Now I wonder if there IS a function which would create a string out of A+C-DDF,A. Not immediately relevant to my situation, but just curious. $\endgroup$
    – GeofAndron
    Mar 11, 2014 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.