Hot answers tagged

8

Cases[{{M, 1, 0, 0, 1, 1, 1, 0}, {A, 0, 0, 0}}, {x_, y__} :> {x, StringJoin[ToString /@ {y}]}]


7

lis = {{M, 1, 0, 0, 1, 1, 1, 0}, {A, 0, 0, 0}}; {First@#, StringJoin[ToString /@ Rest@#]} & /@ lis (* {{M, "1001110"}, {A, "000"}} *)


7

With both StringPattern and RegularExpression the problem is greediness: wildcards will try to match as much as possible. With StringPattern this can be fixed using Shortest: StringReplace[buf, "\\text{" ~~ Shortest[x___] ~~ "}" :> x] With a regular expression a quantifier can be made ungreed with ? (e.g. {(.*?)}), but when you're going that way, you ...


7

Here is an example of formating the srt file. Since it is a text file, it can be exported using the "String" option: exportRST[path_, string_] := Module[{formateLine, strLs,}, formateLine[str_] := Module[{timePos, times, text}, timePos = StringPosition[str, _ ~~ ":" ~~ _ ~~ _ ~~ "." ~~ _ ~~ _]; times = StringTake[str, #] & /@ timePos; text ...


6

text = Drop[Import["http://www.gutenberg.org/cache/epub/36/pg36.txt", "Words"], -20000]; Length@text 42 996


5

I'm going to assume you want this specific char: Unicode Han Character The issue is not with Mathematica's character code conversion, but instead the encoding source. The value you have obtained is in Hex, where you need the decimal to use FromCharacterCode. Hex-> Dec-> Front end FromCharacterCode[Interpreter["HexInteger"]["5929"]] References ...


4

StringTake and Span would be useful. For example, to get the second characters: StringTake[s, 2 ;; ;; 21] (* "LLFOWJZSPLJJHNHQOQLYSOPWQOSZNTTLTOHETNJOJOODOCJFQOJ" *) To get all of the strings: StringTake[s, Array[# ;; ;; 21&, 21]] Another approach would be a combination of Characters and Part: StringJoin[Characters[s][[2 ;; ;; 21]]] (* ...


4

You can get this result by mixing StringExpression with RegularExpression. Regular expressions have the ability to perform a negative look-ahead. This can be used to insure that no numbers which have a decimal followed numbers are matched. getIntegers[s_String] := StringCases[ s, (StartOfString | Whitespace) ~~ u : Repeated["-", {0, 1}] ~~ n : ...


3

If on the off chance you are seeking binary output for numbers then: dat = {{M, 1, 0, 0, 1, 1, 1, 0}, {A, 0, 0, 0}}; {First@#, BaseForm[FromDigits[Rest@#, 2], 2]} & /@ dat Hope this helps.


3

Transpose[{a[[;; , 1]], StringJoin @@@ IntegerString @ a[[;; , 2 ;;]]}]


3

As the @george2079 's suggetion,I post my solution from a friend as an answer,but I'm sure there are more better method can do this.I accept myself answer just for reader.If anyone have post better solution,I'll change the acceptance. $Version "10.3.1 for Microsoft Windows (64-bit) (December 21, 2015)" string = First@Import["file address"]; Rule @@@ ...


2

You can also use FromDigits: FromCharacterCode[FromDigits[#, 16] & /@ StringSplit["\u5929\u4e0a\u4eba\u95f4", "\u"]]


2

One can use here regular expression with Negative Lookahead (?!regex) Before the Match in the same way as shown in this answer: StringCases["blabla ...Hello Hello ... blabla ... Goodbye Goodbye ..", "Hello" ~~ RegularExpression["(?:(?!Hello).)*?"] ~~ "Goodbye"] {"Hello ... blabla ... Goodbye"} StringCases["blabla ...Hello Hello ... blabla ... ...


1

Here is the plain text of the VCF file from your link: BEGIN:VCARD VERSION:2.1 N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E6=B5=8B=E8=AF=95;;;; FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E6=B5=8B=E8=AF=95 TEL;HOME:12345 678 9 END:VCARD Given this, Mathematica's answer is not surprising. Perhaps the odd characters are representatives of a font that is not ...



Only top voted, non community-wiki answers of a minimum length are eligible