I would like to get a customized QDateTime such as:
QString string = "23 April 2012 at 22:51";
QString format = "d MMMM yyyy at hh:mm";
I am unable to as the literal at is not recognized as an 'additional' string but has tokens associated.
a -> AM or PM
t -> timezone information.
Naturally I would take an approach such as an alternative:
QDateTime timeNow = QDateTime::currentDateTime();
QString time1Format = "d MMMM yyyy";
QString time2Format = "hh:mm";
QString time1 = timeNow.toString(time1Format);
QString time2 = timeNow.toString(time2Format);
QString timeConcat = QString(time1 + " at " + time2);
qDebug() << "Time = " << timeConcat;
How can I escape the 'at' keyword in my format?
ap or a Interpret as an AM/PM time. ap must be either "am" or "pm".
You must enclose the at string inside single quotes:
Any sequence of characters enclosed in single quotes will be included
verbatim in the output string (stripped of the quotes), even if it
contains formatting characters. Two consecutive single quotes ("''")
are replaced by a single quote in the output. All other characters in
the format string are included verbatim in the output string.
qDebug() << "Time = " << QDateTime::currentDateTime().toString("d MMMM yyyy 'at' hh::mm");
Related
I tried this format, got output as 1,234,567,890.00
but I need in this format
1,23,567
decimal unitPrice = 1234567890.00m;
TextBox1.Text = Convert.ToDecimal(unitPrice).ToString("##,#0.00");
I guess you can do this by creating a custom number format info for your needs...example is here for your reference -
int yourNumber = 111234;
NumberFormatInfo nfo = new NumberFormatInfo();
nfo.CurrencyGroupSeparator = ",";
nfo.NumberGroupSizes = new int[] { 3, 2 };
string str = yourNumber.ToString("N0", nfo);
Response.Write("answer is : " + str);
I have data in format yyyy-MM-dd hh:mm:ss. It is stored as text.
I want a query that matches a given day(yyyy-MM-dd).
E.g
Select * from test where test MATCH '2014-03-30*'
When i try that, it returns all data excluding that of March 2014.
If i try
Select * from test where test MATCH '2014-04-30*'
It returns all data excluding that of April 2014.
I am puzzled!...i am getting the opposite of what i want!
Any reason for the strange behavior?
This is my full code....testing for date pattern
public List <Transactions> GetTransactionsVirtual(String token)
{
List<Transactions> trans = new ArrayList<Transactions>();
SQLiteDatabase db;
String sql= " Select " + MESSAGE + "," + TDATE + ","+ SERVICE_PROVIDER +
" from " + TABLE_NAME_VIRTUAL + " Where "+ TABLE_NAME_VIRTUAL + " MATCH " + "?" +
" Order by " + TDATE + " DESC";
//check entered string...if date string strip it ..
String pattern="^(19|20)\\d\\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$";
String tokenedit=null;
String newtoken=null;
if (token.matches(pattern))
{
tokenedit= token.replace("-", " ");
Log.e("testtoken", tokenedit);
newtoken = tokenedit+"*" ;
}else
{
newtoken= token+ "*";
}
String [] args= new String[]{newtoken};
Log.e("sqlamatch", sql);
db= this.getReadableDatabase();
Cursor c = db.rawQuery(sql, args);
if(c.moveToFirst())
{
do{
Transactions t=new Transactions();
t.setTransactiondate(c.getString(c.getColumnIndex(TDATE)));
t.setMessage(c.getString(c.getColumnIndex(MESSAGE)));
t.setServiceprovider(c.getString(c.getColumnIndex(SERVICE_PROVIDER)));
//Log.e("msg",t.getMessage().toString());
trans.add(t);
}while(c.moveToNext());
}
return trans;
}
The full-text search mechanism is designed for searching words inside texts.
With the default tokenizer, the three fields of a date (yyyy, MM, dd) are parsed as single, independent words, and the delimiters are ignored.
An FTS query like 2014-03-30* searches for documents (=records) that
contain the word 2014, and
do not contain the word 03, and
do not contain any word beginning with 30.
You need to do a phrase search:
SELECT * FROM test WHERE test MATCH '"2014 03 30"'
If all you data has a fixed format, you should not use an FTS table in the first place.
I want to get first word of a Qstring.
For example String1 = "Read from file1". I want to extract string2 = "Read".
I want to extract substring based on whitespace.
If I encounter a first whitespace in my string1, I need that part of string1 to string2.
Use the split function of QString in this way:
QString firstWord = string1.split(" ").at(0);
If there is no whitespace in the string, the whole string will be returned.
Use QString::split if you want to use all the parts, or QString::section if you just want to grab the first word.
For example, the most basic syntax is:
QString str = "Do re mi";
QString firstWord = str.section(" ", 0, 0);
// firstWord = "Do"
If you need to handle all kinds of weird whitespace, you can use the regex version of the functions:
QString str = "\tDo re\nmi"; // tabs and newlines and spaces, oh my!
QString firstWord = str.section(QRegExp("\\s+"), 0, 0,
QString::SectionSkipEmpty);
// firstWord = "Do"
I would do:
QString s("Read from file1");
QString subStr = s.section(" ", 0, 0, QString::SectionSkipEmpty);
This will work correctly in case of such strings too:
" Read from file1 "
can you please help me with this issue the String class does not have insert method it has only replace :( .
what I need is:
- if I have string "I stackoverflow"
- I need to insert "love " at index 2 to have "I love stackoverflow"
so what I need is insertAt(index, String)
thanks
You can build one of your own. Split the string and concatenate all characters before the index position with the characters of the string you want to insert and with the characters after the index.
eg:
String s = "I stackoverflow";
int index = s.indexOf(" ");
String toInsert = "love ";
String mys = s.substring(0, index) + toInsert + s.substring(index, s.length);
var s:String = "I StackOverflow";
var t:String = s.split(" ").join(" love ");
According to MSDN on DateTime.ToString ToString("s") should always return string in the format of the sortable XML Schema style formatting, e.g.: 2008-10-01T17:04:32.0000000
In Reflector I came to this pattern inside DateTimeFormatInfo.
public string SortableDateTimePattern
{
get
{
return "yyyy'-'MM'-'dd'T'HH':'mm':'ss";
}
}
Does DateTime.ToString("s") return always a string in this format?
Regardless the Culture, Region, ...
Yes it does
Code to test that
var dateTime = DateTime.Now;
var originialString = dateTime.ToString("s");
string testString;
foreach (var c in System.Globalization.CultureInfo.GetCultures(CultureTypes.AllCultures))
{
Thread.CurrentThread.CurrentUICulture = c;
if (c.IsNeutralCulture == false)
{
Thread.CurrentThread.CurrentCulture = c;
}
testString = dateTime.ToString("s");
Console.WriteLine("{0} ", testString);
if (originialString != testString)
{
throw new ApplicationException(string.Format("ToString(s) is returning something different for {0} " , c));
}
}
Yes it does. As others have said it only contains numeric values and string literals (e.g. 'T' and ':'), nothing that is altered by region or culture settings.
Yep. Breaking that pattern down, it's only numeric properties, there's no reference to anything like month or day names in there.
yyyy - 4 digit date
MM - 2 digit month, with leading zero
dd - 2 digit day, with leading zero
T - a literal T
HH - 2 digit hour, with leading zero, 24 hour format
mm - 2 digit minute, with leading zero
ss - 2 digit second, with leading zero