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();
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 invoke an API and after the answer call my method
func getLikes(result:AnyObject!, response:NSHTTPURLResponse! , error:NSError!){
println(result)
}
And when I try print "result" - I get normal JSON in console, but when I try to convert to String
var t = result as String
have "EXEC_BAD_ACCESS".
I try to do print to targetStream (like NSOutputStream), but I don't find how to do it.
How to convert json to string, any ideas?
Okay, i find solution:
If some tyype you can print, but don't know what it is - object implementation Printable interface(printable)
So, you can do that:
var t:String = result.description
And all, good day
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!
Well, thats it!
I need to convert a string text (like"Hrd$457"), into a long value.
The blackberry IDE has a button that do it, but i need do this by code.
Please note that the string is alpha numeric.
THX!
NOTE:
Sorry if my question was not really clear. The IDE button that im talkin about converts the entire string in a long value that makes that string a unique number. The BlackBerry documentation says:
"To create a unique long key, in the BlackBerry® Integrated Development Environment, type a string value.
com.rim.samples.docs.userinfo
Right-click the string and click Convert ‘com.rim.samples.docs.userinfo’ to long."
So, i need to do exactly the same but by code.
I really appreciate your help buddies, and thanks so much for trying to help.
If you are just looking for a number constant for a string you can do the following.
String str = "asdfasdf345asdfasdf";
int asInt = str.hashCode();
long asLong = (long) asInt;
Returns the first 8 bytes of a SHA1 digest as a long. The same result can be obtained interactively using the BlackBerry JDE by highlighting a string, right-clicking, and choosing "Convert '' to long" from the context menu.
long net.rim.device.api.util.StringUtilities.stringHashToLong(String key)
This is another approach. If there are multiple numbers you can loop through the String using the scanner.
Scanner scanner = new Scanner(str);
scanner.useDelimiter("\\D+");
Long number = scanner.nextLong();
Not sure I fully grasp your example, but how's this?
String match = Pattern.compile("\\d+").matcher("Hrd$457").group();
long longValue = Long.parseLong(match).longValue();
Is there a nice way to extract part of a string with linq, example:
I have
string s = "System.Collections.*";
or
string s2 = "System.Collections.Somethingelse.*";
my goal is to extract anything in the string without the last '.*'
thankx I am using C#
The simplest way might be to use String.LastIndexOf followed by String.Substring
int index = s.LastIndexOf('.');
string output = s.Substring(0, index);
Unless you have a specific requirement to use LINQ for learning purposes of course.
You might want a regex instead. (.*)\.\*
With the regex:
string input="System.Collections.Somethingelse.*";
string output=Regex.Matches(input,#"\b.*\b").Value;
output is:
"System.Collections.Somethingelse"
(because "*" is not a word) although a simple
output=input.Replace(".*","");
would have worked :P