I'm using a IwNUI CTextFieldPtr control and I would like to store/use the text attribute stored on the object in a string variable. I need to use that string but I have no clue on the documentation or examples on how to do it... I don't have a complete code sample either because what I'm asking should be pretty straight forward, such as:
CTextFieldPtr login_tUsername;
//textfield init here
std::string c_username;
login_tUsername->GetAttribute("text", c_username);
Please help me, thank you very much!
And other approach, would be something like this, which is by far much closer to what I wanted to do:
CString value;
login_tUsername->GetAttribute("text", value);
std::string thestring = value.Get();
:)
(Credit goes billarhos billarhos)
Well... the best solution I found for this problem was something like this:
login_tUsername->SetEventHandler("textchanged", this, &OnUserEdit);
bool OnUserEdit(CTextField* textField, const char* text)
{
c_username = text;
return true;
}
I don't know why, but it seems you cannot use the textbox text attribute directly.
Cheers!
Related
Thanks for taking the time to look into this.
How do I get rid of all newline characters from a StringBuffer?
The file that i'm reading in looks something like this -
USER|SLACK|TRELLO|BINARY|YO!##!
1234|Joe|||10001!##!
3212|Test1|||10001!##!
2213|Tin Man||24|10001!##!
I tried to use replaceAll(pattern,closure) like shown below. But somehow cant quite get my head around it.
package carriageReturnRemove
class asdf {
static void main(def args){
String str = new File('C:/org.txt').getText()
StringBuilder sb = new StringBuilder(str)
sb = sb.replaceAll(~'/n','')
}
}
The output basically needs to look like this -
USER|SLACK|TRELLO|BINARY|YO!##!1234|Joe|||10001!##!3212|Test1|||10001!##!2213|Tin Man||24|10001!##!
Where am I going wrong? Any help or pointers are greatly appreciated.
Cheers.
Get the lines and join them
new File('C:/org.txt').readLines().join()
You may use this too.
new File("C:/org.txt").text.replaceAll("[\r\n]+","")
I have some strange issue, when try to set parameter in string(redirect). I don't know where the last chars came from
public String register(){
// ...
return "/login?correctReg=true?faces-redirect=true&includeViewParams=true";
}
And output link:
.../login.xhtml?correctReg=true%3F
Where this %3F came from?
The second ? after correctReg=true is encoded automatically to %3f. You probably mean...
return "/login?correctReg=true&faces-redirect=true&includeViewParams=true";
... with &.
I am trying to convert my string to a cstring in an mfc Application. I have searched this forum for hours without any result.
my code is:
void CSokevinduView::OnBnClickedsoker()
{
string O1,O2,O3,info;
ifstream Innfil;
Innfil.open("SQLPResponse.txt");
Innfil.ignore();
getline(Innfil,O1);
getline(Innfil,O2);
getline(Innfil,O3);
getline(Innfil,info);
Innfil.close();
m_sok=info;
m_sok is a cstring btw.
The problem is that "m_sok" dont want to be like "info".
I am very New to this as you can see from my coding.
Thx in advance.
Use the c_str() method of string.
m_sok = info.c_str();
I have a string ="/show/search/All.aspx?Att=A1". How to get the last value after the 'Att=' in efficient way ?
You could do a split on the '=' character.
Example (in C#):
string line = "/show/search/All.aspx?Att=A1";
string[] parts = line.Split('=');
//parts[1] contains A1;
Hope this helps
If you're only dealing with this one URL then both of the other answers would work fine. I would consider using the HttpUtility.ParseQueryString method and just pull out the item you want by key.
Whatever an
efficient way
is...
Try this:
var str = "/show/search/All.aspx?Att=A1";
var searchString = "Att=";
var answer = str.Substring(str.IndexOf(searchString) + searchString.Length);
Do you know of any way to reference an object in the replacement part of preg_replace. I'm trying to replace placeholders (delimited with precentage signs) in a string with the values of attributes of an object. This will be executed in the object itself, so I tried all kinds of ways to refer to $this with the /e modifier. Something like this:
/* for instance, I'm trying to replace
* %firstName% with $this->firstName
* %lastName% with $this->lastName
* etc..
*/
$result = preg_replace( '~(%(.*?)%)~e', "${'this}->{'\\2'}", $template );
I can't get any variation on this theme to work. One of the messages I've been getting is: Can't convert object Model_User to string.
But of course, it's not my intention to convert the object represented by $this to a string... I want to grab the attribute of the object that matches the placeholder (without the percentage signs of course).
I think I'm on the right track with the /e modifier. But not entirely sure about this either. Maybe this can be achieved much more simple?
Any ideas about this? Thank you in advance.
Like I commented to Paul's answer: in the meanwhile I found the solution myself. The solution is much more simple than I thought. I shouldn't have used double quotes.
The solution is as simple as this:
$result = preg_replace( '~(%(.*?)%)~e', '$this->\\2', $template );
Hope this helps anyone else for future reference.
Cheers.
Check out preg_replace_callback - here's how you might use it.
class YourObject
{
...
//add a method like this to your class to act as a callback
//for preg_replace_callback...
function doReplace($matches)
{
return $this->{$matches[2]};
}
}
//here's how you might use it
$result = preg_replace_callback(
'~(%(.*?)%)~e',
array($yourObj, "doReplace"),
$template);
Alternatively, using the /e modifier, you could maybe try this. I think the only way to make it work for your case would be to put your object into global scope
$GLOBALS['yourObj']=$this;
$result = preg_replace( '~(%(.*?)%)~e', "\$GLOBALS['yourObj']->\\2", $template );