有没有人对如何创建 private void btnSave_Click(object sender, EventArgs e)
{
string imageFilePath = null;
string dataFilePath = null;
ImageFormat format = System.Drawing.Imaging.ImageFormat.Png;
try
{
// Image data
imageFilePath = promptForFilePath("Save Chart image", "PNG Files (*.png)|*.png|JPEG Files (*.jpg,*.jpeg)|*.jpg;*.jpeg|BMP Files (*.bmp)|*.bmp|All Files (*.*)|*.*");
if (!String.IsNullOrWhiteSpace(imageFilePath))
{
switch (Path.GetExtension(imageFilePath).Replace(".", "").ToLower())
{
case "jpeg":
case "jpg":
format = ImageFormat.Jpeg;
break;
case "png": format = ImageFormat.Png;
break;
case "bmp": format = ImageFormat.Bmp;
break;
}
this.graph.SaveImage(imageFilePath, format);
}
// XML data
dataFilePath = promptForFilePath("Save Chart data","XML Files (*.xml)|*.xml|All Files (*.*)|*.*");
if (!String.IsNullOrWhiteSpace(dataFilePath)) this.graph.Serializer.Save(dataFilePath);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message, "btnSave_Click Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
}
}
string promptForFilePath(string title = "Save File", string fileFilter = "All Files (*.*)|*.*")
{
string result = null;
SaveFileDialog saveFileDialog = null;
try
{
saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = title;
saveFileDialog.Filter = fileFilter;
if(saveFileDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
result = saveFileDialog.FileName;
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message, "saveChartData Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (saveFileDialog != null)
{
saveFileDialog.Dispose();
saveFileDialog = null;
}
}
return result;
}
有任何想法,function
接受来自标准input
和prints
他们mirrored
的文字?
例如:
输入:
day time you is
输出:
yad emit ouy si
答案 0 :(得分:0)
您可以使用generator
循环浏览word
中的每个string
并将其反转。要反转它,我们使用slicing
高级-1
作为step
值。然后我们想要在每个单词之间加入所有反转的单词和space
。我们可以使用str.join
执行此操作。
将上述内容放在一起,我们得到function
:
def mirror(s):
return ' '.join(w[::-1] for w in s.split())
的示例:
>>> mirror("day time you is")
'yad emit uoy si'
>>> mirror("hello how are you")
'olleh woh era uoy'
答案 1 :(得分:0)
def mirrow(stringToMirror) :
stringToMirrorList = StringToMirror.split(" ")
for x in stringToMirrorList :
print x(::-1) + " "