diff --git a/BaseLib/StringTools.cpp b/BaseLib/StringTools.cpp
index 7acb1e4913ec6fc4de6e5ccb4fbeea65d7f8b1c7..738af0fcd3045b99177a0487f7c761b48d88c26e 100644
--- a/BaseLib/StringTools.cpp
+++ b/BaseLib/StringTools.cpp
@@ -12,13 +12,15 @@
  *
  */
 
+#include "StringTools.h"
+
 #include <algorithm>
 #include <cctype>
+#include <iomanip>
 
 // ThirdParty/logog
 #include "logog/include/logog.hpp"
 
-#include "StringTools.h"
 
 namespace BaseLib
 {
@@ -75,6 +77,14 @@ std::string stringToUpper(std::string const& str)
 	std::transform(s.begin(), s.end(), s.begin(), (int(*)(int)) std::toupper);
     return s;
 }
+
+std::string padLeft(std::string const& str, int maxlen, char ch)
+{
+	std::stringstream ss(str);
+	ss << std::right << std::setw(maxlen) << std::setfill(ch) << str;
+	return ss.str();
+}
+
 } // end namespace BaseLib
 
 #ifdef MSVC
diff --git a/BaseLib/StringTools.h b/BaseLib/StringTools.h
index 1754f50d08762550cd3c124163b8cea44f566b4a..9a9411007df37806d7f613e13800372d1f281125 100644
--- a/BaseLib/StringTools.h
+++ b/BaseLib/StringTools.h
@@ -74,6 +74,11 @@ void simplify(std::string &str);
  */
 std::string stringToUpper(std::string const& str);
 
+/**
+ * Returns the string which is right aligned with padding on the left.
+ */
+std::string padLeft(std::string const& str, int maxlen, char ch=' ');
+
 } // end namespace BaseLib
 
 #ifdef MSVC