עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

מחרוזת ב-C# - איך מציבים תו במקום מסויים?

Featured Replies

פורסם

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine();
Console.WriteLine(" *-------------------*");
string result = " | |";
Console.WriteLine(" |-------------------|");
Console.WriteLine(" | |");
Console.WriteLine(" | 7 8 9 |");
Console.WriteLine(" | |");
Console.WriteLine(" | 4 5 6 |");
Console.WriteLine(" | |");
Console.WriteLine(" | 1 2 3 |");
Console.WriteLine(" | |");
Console.WriteLine(" | + 0 - |");
Console.WriteLine(" | |");
Console.WriteLine(" *-------------------*");
Console.WriteLine();

double a;
double b;
char operation;

result[10] = '5';

Console.Write("Enter a mathematical phrase: ");
a = double.Parse(Console.ReadLine());
operation = char.Parse(Console.ReadLine());
b = double.Parse(Console.ReadLine());
Console.Write("=");
Calculator cal = new Calculator(a, b);

switch (operation)
{
case '+':
Console.WriteLine(cal.Add(a, b));
break;
case '-':
Console.WriteLine(cal.Sub(a, b));
break;
case '*':
Console.WriteLine(cal.Mul(a, b));
break;
case '/':
Console.WriteLine(cal.Div(a, b));
break;
case '%':
Console.WriteLine(cal.Remainder(a, b));
break;
default:
Console.WriteLine("Wrong Option");
break;
}
}
}
}

אני רוצה להציב את התוצאה החל ממקום 3 במחרוזת result.

thank you helpers :]

פורסם

אין פונקציה שעושה את זה. אתה צריך לעשות את זה ידנית ע"י הפונקציות הקיימות (או ע"י החלפה תו אחר תו, או ע"י בנייה מחדש של המחרוזת באמצעות string.Format).

פורסם
  • מחבר

אהע

ועוד משהו, אני רוצה לכתוב ביטוי מתמטי בשורה אחת ולא ללחוץ ENTER אחרי כל קלט

וה-Console.Read לא עובד לי, לא בטוח איך עובדים איתו כל כך.

פורסם

תנסה לעשות שירשור.

אני לא מומחה ב C# אבל זה די דומה ל JAVA.

דוג' -

	
public static void main(String[] args) {
String a = "abcef";
String b = "d";

String c = a.substring(0, 3) + b.toString() + a.substring(3, a.length());

System.out.println(a+"\n"+b+"\n"+c);

}

פלט -

abcef
d
abcdef

פורסם
  • מחבר

לא שהבנתי משהו אבל וטבר

פורסם

שתיהם פשוט לא הבינו מה שאתה רוצה.. בכל מקרה, לא נראה לי שיש דרך מובנת לעשות את זה ב .NET אז אתה יכול לעשות את זה בצורה מכוערכת של מחיקת המסך בכל אות שמכניסים, או להשתמש בפקודות WIN32 בעזרת interop לפקודות הבאות:

http://forums.devshed.com/showpost.php?p=645101&postcount=4

תסתכל פה:

http://support.microsoft.com/kb/319257

פורסם

אהע

ועוד משהו, אני רוצה לכתוב ביטוי מתמטי בשורה אחת ולא ללחוץ ENTER אחרי כל קלט

וה-Console.Read לא עובד לי, לא בטוח איך עובדים איתו כל כך.

Console.Read קורא כל פעם תו בודד. מה אתה רוצה לעשות איתו?

אם אתה רוצה לקרוא את כל הביטוי המתמטי בשורה אחת, אז תשתמש ב-ReadLine, ואז תחתוך את המחרוזת ידנית (באמצעות Split, IndexOf וכד').

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.