String append in java

I am constructing single string value based on some other string details, which is as below. But don’t wants to add if any of DTO value is null or empty. How can I add it in java. String dummyVal = new StringBuffer ("<b> test Id </b> ").append(someDTO.getId()).append(", ") .append("<b> Type: </b> ").append(someDTO.getType()).append(", ") .append("<b> Date:… Read More String append in java

How to replace first letter and last letter in array of strings

I am trying to replace in the array of strings in EVERY word, the first letter with A and the last letter with Z My Array : String[] replaceFirstLetter1 = new String[]{"Java Bople Orange New Dog Cat"}; This is what I am trying: public static String[] replaceFirstLetterWithZ(String[] replaceFirstLetter) { String[] tempTable = new String[replaceFirstLetter.length]; StringBuilder… Read More How to replace first letter and last letter in array of strings

Why is my scanner skipping every other user input when I print my StringBuilder?

public static void main(String[] args) { String welcomeMsg = "Enter inputs. Leave blank and hit Enter when done." Scanner sc = new Scanner(System.in); System.out.println(welcomeMsg); StringBuilder attendees = new StringBuilder(); while (!sc.nextLine().equals("")){ attendees.append(sc.nextLine()); } System.out.println(attendees); } The scanner seems to be working fine. I can input say, a then hit enter. Hit b and hit enter.… Read More Why is my scanner skipping every other user input when I print my StringBuilder?

How to call the Win32 GetCurrentDirectory function from C#?

The prototype of GetCurrentDirectory DWORD GetCurrentDirectory( [in] DWORD nBufferLength, [out] LPTSTR lpBuffer ); DWORD is unsigned long, LPTSTR is a pointer to wchar buffer in Unicode environment. It can be called from C++ #define MAX_BUFFER_LENGTH 256 int main() { TCHAR buffer[MAX_BUFFER_LENGTH]; GetCurrentDirectory(MAX_BUFFER_LENGTH, buffer); return 0; } I tried to encapsulate this win32 function in C#,… Read More How to call the Win32 GetCurrentDirectory function from C#?

Why is StreamWriter adding random bytes to a file?

I’m trying to translate a virtual key code with ToAsciiEx() and write it to a debug file. For some reason, the output file contains a load of random trash bytes interspersed with the key codes I want to log. I’m importing ToAsciiEx() like this: [DllImport("user32.dll")] static extern int ToAsciiEx(uint uVirtKey, uint uScanCode, byte[] lpKeyState, [Out]… Read More Why is StreamWriter adding random bytes to a file?

Convert ASCII to hex

I want convert ASCII values to hex. In Java, I often use the function: private static String asciiToHex(String asciiStr) { char[] chars = asciiStr.toCharArray(); StringBuilder hex = new StringBuilder(); for (char ch : chars) { hex.append(Integer.toHexString((int) ch)); } return hex.toString(); } Is there any method in Dart to convert to hex value like Integer.toHexString in… Read More Convert ASCII to hex

Trying to map "similar looking" tuples returned from multiple functions to one variable

Say there is a library with code of this form: public class SomeLib { public (bool WasOk, string Message) DoCheck(string fileName) { // do something here to check the file. return (true, "all good"); } public (bool WasOk, string Message) DoCheck(byte[] fileBytes) { // do something here to check the file as bytes return (true,… Read More Trying to map "similar looking" tuples returned from multiple functions to one variable