"12345" として分割する操作を実行してforループを使用して追加する必要があります。 が好き:1 + 2 + 3 + 4 + 5 、その後、私はasp.netとC#でここに私のコードを掲載しています15.文字列内の文字を分割してCで合計を実行する方法
としてラベルの動作の出力を表示
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace proj1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int v1 = 0, x = 0; //sum = 0, l, r;
// char Q, W, E, R, T, Y, U, I, O, P, A, S, D, F, G, H, J, K, L, Z, X, C, V, B, N, M;
string str = TextBox1.Text;
Label1.Text = ("Result");
Label2.Text = ("You have Entered");
Label5.Text = (":");
Label8.Text = str.ToString();
// Array word[] = new Array();
string str1 = str.Replace(" ", "").Replace("`", "").Replace("~", "").Replace("!", "")
.Replace("@", "").Replace("#", "").Replace("$", "").Replace("%", "").Replace("^", "")
.Replace("&", "").Replace("*", "").Replace("(", "").Replace(")", "").Replace("-", "")
.Replace("_", "").Replace("=", "").Replace("+", "").Replace("{", "").Replace("}", "")
.Replace("|", "").Replace("[", "").Replace("]", "").Replace(":", "").Replace(";", "")
.Replace("'", "").Replace(",", "").Replace(".", "").Replace("/", "").Replace("?", "")
.Replace(">", "").Replace("<", "").Replace("1", "").Replace("2", "").Replace("3", "")
.Replace("4", "").Replace("5", "").Replace("6", "").Replace("7", "").Replace("8", "")
.Replace("9", "").Replace("0", "");
string str2 = str1.ToUpper();
string str3 = str2.Replace("A", "1").Replace("B", "2").Replace("C", "3").Replace("D", "4").Replace("E", "5").Replace("F", "8")
.Replace("G", "3").Replace("H", "5").Replace("I", "1").Replace("J", "1").Replace("K", "2").Replace("L", "3")
.Replace("M", "4").Replace("N", "5").Replace("O", "7").Replace("P", "8").Replace("Q", "1").Replace("R", "2")
.Replace("S", "3").Replace("T", "4").Replace("U", "6").Replace("V", "6").Replace("W", "6").Replace("X", "5")
.Replace("Y", "1").Replace("Z", "7");
string word1 = str3.ToString();
String[] word = word1.ToString().Split();
for (int i = 0; i < word.Length; i++)
{
x = ((x + (Convert.ToInt32(word[i]))));
}
int value1 = x;
Label3.Text = ("Value Of Charecters");
Label6.Text = (":");
Label9.Text = value1.ToString();
Label4.Text = ("Summed Value");
Label7.Text = (":");
Label10.Text = ("");
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="proj1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<h1>Project - 1</h1>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td class="auto-style1">Enter Your Text</td>
<td>:</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Width="362px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1"></td>
<td></td>
<td>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td class="auto-style1"></td>
<td></td>
<td></td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="Label1" runat="server"></asp:Label>
</td>
<td></td>
<td></td>
</tr>
<tr>
<td class="auto-style1"></td>
<td></td>
<td></td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="Label2" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Label5" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Label8" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="Label3" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Label6" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Label9" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="Label4" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Label7" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Label10" runat="server"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
実際にこの作業を実行する必要があります
- 入力文字列はテキストボックスに入力してください。ボタンをクリックすると
- 文字を保存し、入力を表示
- をExcelの指定された数字に置き換えてください。
- a = 1、b = 2、c = 3、d = 4、e = 5のように合計を実行すると、その合計の結果として 15を出力として表示する必要があります。 :合計の値は、私がLINQのを使用することをお勧めのexeファイル
コードの聖なる壁、バットマンであるJavaスクリプトではありません。 – Abion47