My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Friday, August 23, 2024

Python's F-String for String Interpolation and Formatting

Interpolating Values and Objects in F-Strings

In latest python, F-strings make the string interpolation process intuitive, quick, and concise. The syntax is similar to what you used with .format(), but it’s less verbose. You only need to start your string literal with a lowercase or uppercase f and then embed your values, objects, or expressions in curly brackets at specific places:

>>> name = "Jane"
>>> age = 25
>>> f"Hello, {name}! You're {age} years old."
'Hello, Jane! You're 25 years old.'

Earlier in Python 3.6 we had the Modulo Operator, % for thsi purpose

The modulo operator (%) was the first tool for string interpolation and formatting in Python and has been in the language since the beginning. Here’s what using this operator looks like in practice:

>>> name = "Jane"
>>> "Hello, %s!" % name
'Hello, Jane!'
Or, see the next example
>>> name = "Jane"
>>> age = 25

>>> "Hello, %s! You're %s years old." % (name, age)
'Hello, Jane! You're 25 years old.'
Or, see the next example for decimal point formatting
>>> "Balance: $%.2f" % 5425.9292
'Balance: $5425.93'

Friday, June 1, 2012

Strings tool from Sysinternals: String Obfuscation Testing to find Hardcoded Strings in source code

It was in 1996, that Sysinternals website was Created. Mark Russinovich and Bryce Cogswell hosted their advanced system utilities and technical information. The Sysinternals utilities help you manage, troubleshoot and diagnose your Windows systems and applications.

One of these Tools is Strings. Current version is v2.5

At times, DLL, executable, .lib and object files have embedded UNICODE/ Ascii strings that you cannot easily see with a standard ASCII strings or grep programs. Strings is a utility that scans the file you pass it. By default, it searches for strings of length of 3 or more. Wonderful part is that it works on nearly all flavors of Windows including Win 95!

This became such a hit that even Microsoft has given great interest in this project. And, the result is that today you can download this utility directly from Microsoft Website. Yes!! MS holds it now!!
Download from: http://technet.microsoft.com/en-us/sysinternals/bb897439.aspx

Using Strings program:-
1. Open a command prompt
2. Run strings
3. There are multiple options that are described as below:-

usage: strings [-a] [-f offset] [-b bytes] [-n length] [-o] [-q] [-s] [-u]
Strings takes wild-card expressions for file names, and additional command line parameters are defined as follows:
-o Print offset (not of much use)
-n This is the minimum string length (default is 3)
-q Quiet mode
-s Recursive traversal of subdirectories
-a ASCIIonly search [default is Unicode and Ascii]
-b how many Bytes in file to scan
-f File offset from which to start scanning.
-u Unicode-only search (Unicode and Ascii is default)
Happy catching your hardcoded strings. Make your product more secure.