I get the line: Ivan 5 rubles 20 kopecks. (the value in bold is always different) How to break it all into 3 variables: name = Ivan; rub = 5 rubles; kop = 20 kopecks.
3 answers
If the structure is always the same, then you can go from the end, it will be the easiest way.
String str = "Мне все равно как этого парня зовут 1 рубль 1 копейка"; String[] split = str.Split(' '); Int32 splitCount = split.Count(); string kop = String.Join(" ", split.Skip(splitCount - 2)); string rub = String.Join(" ", split.Skip(splitCount - 4).Take(2)); string name = String.Join(" ", split.Take(splitCount - 4)); - Your method works, only sometimes it is found 12-23,26,28 kopecks (( - user222349
- Everything, he figured it out. Thanks - user222349
|
- oneand if there is 1 ruble? - tCode
- This will add to the regular season or
|- nick_n_a - 2the question indicates that the variable values are bold. The word "rubles" is not bold; therefore, it is logical to assume that it is immutable. If this is not the case, then modifying it is quite simple by adding through
|literal ruble as above advises @nick_n_a - DreamChild - @DreamChild and the fact that the name may change does not bother you? - tCode
- one@tCode And this is not a question for me "ok or not ok." This is a topstarter. Is it somewhere in the problem said about the morphology? You overcomplicate too. In this case, you will need to write a parser that takes into account the rules for the coordination of numerals and nouns in Russian. As a last resort, you can replace the literals "rubles" and "kopecks" with groups of any characters - DreamChild
|
string[] s = String.Split(' '); name = s[0]; rub = s[1] + " " + s[2]; kop = s[3] + " " + s[4]; |
Split, cycle, conditions, plusint.TryParse. Carefully put everything together. It is possible to loop without multipleif. - nick_n_aint.TryParseseparates numbers from words. In my opinion, this task must be done independently. - nick_n_a