How to change a public location,how to get a public variable

My idea is to access saved data. But I have a function that I may need like 4 or 5 times so I wanted to make a script where we can change the location of the data that I want to acces. But I dont know how to do it.
Like :


public string str = ; 

void change_button_value ()
    button.getComponent<Text>().text = str


I want to be able of changing the str value by an other location of an other string.


change_button_value(“this is my string, it can be anything i want”);

void change_button_value(string s){
    //plug "s" in to whatever you want
    String myNewString = s;