RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

全部问题

Martin Hope
Garp
Asked: 2024-12-28 14:54:27 +0000 UTC

访问私有变量

  • 6

这种对私有变量的访问(不改变它们!)——如何安全和可接受?

class MyClass:
    def __init__(self):
        self.__private_var = 66


class_instance = MyClass()
print(class_instance._MyClass__private_var)
python
  • 1 个回答
  • 43 Views
Martin Hope
GreenX5
Asked: 2024-12-28 08:00:36 +0000 UTC

如何为动态创建的按钮创建组处理程序?

  • 5

动态创建按钮并将其添加到 LinearLayout

fun but_gen (line:String, dec:String, contactframe:LinearLayout, tag:String) {
    val contacts = "Vasya|Fedya|Masha".split("|")
    for (contact in contacts) {
        val button = Button(this).apply {
            text = contact
        }
        contactframe.addView(button)
    }
}

如何为他们创建一个组监听器setOnClickListener并通过文本进行识别?如果它是在按钮之前创建的,它还能运行吗?

android-studio
  • 1 个回答
  • 17 Views
Martin Hope
Лена
Asked: 2024-12-28 06:55:44 +0000 UTC

转换字符串,删除空格

  • 6

有一行:

const txt = '    #text # textx   saad #asadsas   '

执行 3 项操作的最佳方法是什么

  1. 删除行首的空格
  2. 删除 # 符号后面的所有空格
  3. 将所有等于或大于 2 的空格替换为单个空格
javascript
  • 4 个回答
  • 70 Views
Martin Hope
Galis
Asked: 2024-12-28 03:25:45 +0000 UTC

解决方法:重复一个字符串,直到总长度超过100

  • 5
name = input("Your name: ")
while len(name) > 100:
    print(name)
    name *=1 

我写了这个,但是代码不正确。
我需要复制之前的名字100。

我不明白,它应该是这样的:

#1 Маша 
#2 МашаМаша
#3 МашаМашаМаша
#так далее я не понимаю как написать код. 
python
  • 2 个回答
  • 67 Views
Martin Hope
ArTimon
Asked: 2024-12-28 01:44:36 +0000 UTC

如何在每次单击按钮时清除文本框

  • 5

我无法理解它的工作原理,在button_onclick事件的开头我调用textBox.Clear(),即我希望每次单击此按钮时,文本框都会被清除,但如果我不关闭表单,则不会发生这种情况,输出结果会累积。在这段代码中:

private void but_OK_Click(object sender, EventArgs e)
        {
            txt_output.Clear();
            string str_input = txt_input.Text;

            Format_Rule(str_input);

            for (int i = 0; i < str_in.Count; i++)
            {
                txt_output.Text += str_in.GetKey(i) + " " + str_in.Get(i) + Environment.NewLine;
            }
        }

这是所有代码

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ТЯП_Лаб1
{
    public partial class Form1 : Form
    {
        NameValueCollection str_in = new NameValueCollection();

        string alphabet = "abcdefghijklmnopqrstuvwxyz";
        string alpha_number = "0123456789";
        string alpha_operand = "-+*/";

        private bool Search_Operand(string str)
        {
            for (int i = 0; i < alpha_operand.Length; i++)
            {
                if (str.Contains(alpha_operand[i]))
                {
                    return true;
                }
            }
            return false;
        }

        private bool Search_Number(string str)
        {
            for (int i = 0; i < alpha_number.Length; i++)
            {
                if (str.Contains(alpha_number[i]))
                {
                    return true;
                }
            }
            return false;
        }

        private bool Search_Word(string str)
        {
            for (int i = 0; i < alphabet.Length; i++)
            {
                if (str.Contains(alphabet[i]))
                {
                    return true;
                }
            }
            return false;
        }
        
        private void Format_Rule(string str )
        {
            string str_oper = "";
            string str_set = "";

            if (!Search_Operand(str))
            {
                for (int i = 0; i < str.Length; i++)
                {
                    if(i == str.Length)
                        str_set += str[i];
                    else
                        str_set += str[i] + " | ";
                }

                str_in.Add("S->", "T");
                str_in.Add("T->", "T | TF");
                str_in.Add("F->", str_set);

            }
            else
            {
                for (int i = 0; i < str.Length; i++)
                {
                    if(str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
                    {
                        if(i != str.Length)
                            str_oper += str[i] + "T" + " | ";
                        else
                            str_oper += str[i] + "T";
                    }
                    else
                    {
                        if(i != str.Length)
                            str_set += str[i] + " | ";
                        else
                            str_set += str[i];
                    }
                }

                str_in.Add("S->", str_oper);
                str_in.Add("T->", "T | TF");
                str_in.Add("F->", str_set);
            }
        }

        public Form1()
        {
            InitializeComponent();
        }

        private void but_OK_Click(object sender, EventArgs e)
        {
            txt_output.Clear();
            string str_input = txt_input.Text;

            Format_Rule(str_input);

            for (int i = 0; i < str_in.Count; i++)
            {
                txt_output.Text += str_in.GetKey(i) + " " + str_in.Get(i) + Environment.NewLine;
            }
        }
    }
}

应该如何

怎么不应该这样

c#
  • 1 个回答
  • 33 Views
上一页
下一页

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5