How to center a string using String.format?

I quickly hacked this up. You can now use StringUtils.center(String s, int size) in String.format. import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.assertThat; import org.junit.Test; public class TestCenter { @Test public void centersString() { assertThat(StringUtils.center(null, 0), equalTo(null)); assertThat(StringUtils.center(“foo”, 3), is(“foo”)); assertThat(StringUtils.center(“foo”, -1), is(“foo”)); assertThat(StringUtils.center(“moon”, 10), is(” moon “)); assertThat(StringUtils.center(“phone”, 14, ‘*’), is(“****phone*****”)); assertThat(StringUtils.center(“India”, 6, ‘-‘), is(“India-“)); assertThat(StringUtils.center(“Eclipse … Read more

How to get the given date string format(pattern) in java?

import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; public class NewClass { private static final String[] formats = { “yyyy-MM-dd’T’HH:mm:ss’Z'”, “yyyy-MM-dd’T’HH:mm:ssZ”, “yyyy-MM-dd’T’HH:mm:ss”, “yyyy-MM-dd’T’HH:mm:ss.SSS’Z'”, “yyyy-MM-dd’T’HH:mm:ss.SSSZ”, “yyyy-MM-dd HH:mm:ss”, “MM/dd/yyyy HH:mm:ss”, “MM/dd/yyyy’T’HH:mm:ss.SSS’Z'”, “MM/dd/yyyy’T’HH:mm:ss.SSSZ”, “MM/dd/yyyy’T’HH:mm:ss.SSS”, “MM/dd/yyyy’T’HH:mm:ssZ”, “MM/dd/yyyy’T’HH:mm:ss”, “yyyy:MM:dd HH:mm:ss”, “yyyyMMdd”, }; /* * @param args */ public static void main(String[] args) { String yyyyMMdd = “20110917”; parse(yyyyMMdd); … Read more

Changing the date format to yyyy-mm-dd

UPDATED: NEW ANSWER Here is a solution that will do the job! The sub routine includes a function that does the replacement (the function itself is really useful!). Run the sub and all occurances in column A will be fixed. Sub FixDates() Dim cell As range Dim lastRow As Long lastRow = range(“A” & Rows.count).End(xlUp).Row … Read more

python string format calling a function

Not sure if you can modify the object, but you could modify or wrap the object to make the functions properties. Then they would look like attributes, and you could do it as class WrapperClass(originalRequest): @property def full_name(self): return super(WrapperClass, self).full_name() “{0.full_name} {0.full_last_name} and my nick name is {0.full_nick_name}”.format(user) which IS legal.

Convert a String to Double – Java

Have a look at java.text.NumberFormat. For example: import java.text.*; import java.util.*; public class Test { // Just for the sake of a simple test program! public static void main(String[] args) throws Exception { NumberFormat format = NumberFormat.getInstance(Locale.US); Number number = format.parse(“835,111.2”); System.out.println(number); // or use number.doubleValue() } } Depending on what kind of quantity you’re … Read more

pandas xlsxwriter, format table header – not sheet header

I think you need first reset default header style, then you can change it: pd.core.format.header_style = None All together: import pandas as pd data = pd.DataFrame({‘test_data’: [1,2,3,4,5]}) writer = pd.ExcelWriter(‘test.xlsx’, engine=”xlsxwriter”) pd.core.format.header_style = None data.to_excel(writer, sheet_name=”test”, index=False) workbook = writer.book worksheet = writer.sheets[‘test’] font_fmt = workbook.add_format({‘font_name’: ‘Arial’, ‘font_size’: 10}) header_fmt = workbook.add_format({‘font_name’: ‘Arial’, ‘font_size’: 10, … Read more