Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have string like this :

Isi Voucher Regular 10K seharga Rp 10,400.00 pada 13/12/16 16:52 ke 6285811111111 SUKSES, Saldo: Rp 3,482,350.00, TID:0071272220111111111.


I want get value ->
Saldo: Rp 3,482,350.00


Hope you help

What I have tried:

int startIndex = strKeterangan.IndexOf("Rp");
 int endIndex = strKeterangan.IndexOf(",", startIndex);
 sisaStok = strKeterangan.Substring(startIndex, endIndex - startIndex);
Posted
Updated 29-Dec-16 5:19am

Use a regex:
C#
public static Regex regex = new Regex(
      "(?<=Saldo:\\sRp\\s+)[\\d,\\.]*(?=,\\s)",
    RegexOptions.Multiline
    | RegexOptions.IgnorePatternWhitespace
    | RegexOptions.Compiled
    );
...
// Capture the first Match, if any, in the InputText
Match m = regex.Match(InputText);
if (m.Success)
   {
   string value = m.Value;
   ...
 
Share this answer
 
Comments
ulungss 1-Jan-17 21:35pm    
what if string like this :
XR50.0838933222221 Hrg=48800 SUKSES SN: 5186121284136. Sisa Saldo Rp.17110142

and i want get value 17110142 ?, give me teqnique when i get all Saldo.

hope you help
OriginalGriff 2-Jan-17 3:29am    
That's a trivial modification - you should be able to work it out for yourself.
Get a copy of Expresso
http://www.ultrapico.com/Expresso.htm
It's free, and it examines and generates Regular expressions.
It'll help you design and test regexes.
If you can't get it, show us what you tried.
Try the regex way:
using System;
using System.Text.RegularExpressions;

public class Program
{
	public static void Main()
	{
		string str = "Isi Voucher Regular 10K seharga Rp 10,400.00 pada 13/12/16 16:52 ke 6285811111111 SUKSES, Saldo: Rp 3,482,350.00, TID:0071272220111111111.";
		Regex regex = new Regex(@"Saldo: Rp [\d,\.]+(?=,)");
		Match match = regex.Match(str);
		if (match.Success)
		{
			Console.WriteLine(match.Value);
		}
	}
}

Learn:
1. The 30 Minute Regex Tutorial[^]
2. Use regex in c#[^]
 
Share this answer
 
v2
Comments
ulungss 29-Dec-16 11:30am    
nice... great. thank alot.. peter.
The original string is:
Isi Voucher Regular 10K seharga Rp 10,400.00 pada 13/12/16 16:52 ke 6285811111111 SUKSES, Saldo: Rp 3,482,350.00, TID:0071272220111111111.

In the code you searh the first "," with
int endIndex = strKeterangan.IndexOf(",", startIndex);

this find the "," inside 3,482,350.00
if you use LastIndexOf to search the last "," in the string with:
int endIndex = strKeterangan.LastIndexOf(",", startIndex);

you will find what you want
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900