# Tag Info

0

Given string and size, outputs list of character code lists of size, and corresponding x-graph string. Add white-space removal / tally / etc. if desired: test = "This is a test" xGraphs[string_, size_] := With[{chars = ToCharacterCode[string]}, {p = Partition[chars, size, 1], FromCharacterCode /@ p}] xGraphs[test, 2] xGraphs[test, 4] (* {{{84, 104}, ...

5

It doesn't work because it's simply not correct syntax. String patterns and expression patterns are not interchangeable. Each works only with its own set of functions: string patterns work only in StringMatchQ and expression patterns only work in MatchQ. In function definitions you can only use expression patterns. You can use something like this ...

0

I came upon this question when trying to add a number in scientific notation to a string in the label of a plot, which requires (or at least looks better) if the number is written with the exponents properly typeset (i.e. like $1.453\times 10^4$). This is not really what's in the question but it's not covered exaclty in any of the answers so far and this is ...

0

This question touches on a lot of things and I am not sure which elements to focus on. I guess I'll take it in reverse order, as you state that the reason for the question is: I'm currently making a small program in mma which will help me enter matrices manually because it's cumbersome to type in every single ,{} for each row/column. Yes, that is ...

1

For a general case, in which the string may be in any position, also this is possible: MyList /. s_String :> ToExpression[ToUpperCase[s]] Care should be taken if the numbers come from another program using the common scientific notation, such as 1.0E+7. In this case, the following may help: myList /. s_String :> ...

0

A little more general: myList = {-0.0000396, -0.0000187167, "0.10259130990561813-0.0677132394802944i"} (ToExpression /@ myList) /. i -> I Head /@ %

1

myList = {-0.0000396, -0.0000187167, "0.10259130990561813-0.0677132394802944i"} ; myNewList = myList/.{x_, y_, z_} :> {x, y, ToExpression@StringReplace[z, "i" -> "I"]} {-0.0000396, -0.0000187167, 0.102591 - 0.0677132 I} Head /@ myNewList {Real, Real, Complex}

Top 50 recent answers are included