Can you please tell me how can I parse a string if I create instances of Label? Here is the constructor:

public TextManager(RichTextBox rtb, Label insideTemp, Label outsideTemp, Label huMidity, Label lightLevel) { _displayWindow = rtb; _insideTemperature = insideTemp; _outsideTemperature = outsideTemp; _humidityLevel = huMidity; _lightLevel = lightLevel; } 

Then I have to parse the input string, say - "temp1 = 25C, temp2 = 33, humidity = 85, light level = 57 \ r"; And I don’t understand how to work with a copy, or I don’t understand it at all ... Please, give me good advice. I would be grateful for any answer.

Closed due to the fact that the essence of the issue is not clear to the participants: aleksandr barakin , user194374, Alex , Denis Bubnov , Qwertiy Nov 28 '16 at 20:02 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 3
    You can parse the string by splitting it into Split (',') substrings; it is even better to use regulars. But it’s not at all clear what you are doing and where does the 'Label instances' here - koks_rs
  • 2
    @nick_n_a, aah, what's going on here? I do not understand what you and the vehicle are writing about. - koks_rs 2:01
  • Do you want to enter information from the line of the form: "temp1 = 25C, temp2=33, humidity = 85, light level = 57 \r" and display the values ​​in 4 corresponding Label ? - user227049
  • It is required to clarify the question. If it concerns the parsing of lines, then what does the label have to do with it - use Split and that's it; if it concerns label'ov, then it is necessary to clarify what specifically is not clear. - AK

1 answer 1

Terrible execution, but God bless him ... you need to think about the output of information and refactoring code. In the version of the question that is now, the answer is as follows:

 string str="temp1 = 25C, temp2 = 33, humidity = 85, light level = 57 \r"; str=str.Replace(" \r", string.Empty); string[] parsedstr=str.split(", "); Label insideTemp= new Label(); Label outsideTemp= new Label(); Label huMidity= new Label(); Label lightLevel= new Label(); insideTemp.Text=parsedstr[0].split(" = ")[1]; outsideTemp.Text=parsedstr[1].split(" = ")[1]; huMidity.Text=parsedstr[2].split(" = ")[1]; lightLevel.Text=parsedstr[3].split(" = ")[1]; RichTextBox rtb = new RichTextBox();//хз зачем он вам. TextManager TxtM = new TextManager(rtb, insideTemp, outsideTemp, huMidity, lightLevel) 
  • I did it all the same through regular expressions. 'code' private string parse (string regExp, string input) ' - JDo
  • one
    If this resolves the problem, answer your own question and select it with a solution. - xSx