Click here to Skip to main content
15,906,626 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have string...
----------56628885466----655277772323777---
I want to process this string..
1.i want string string to split like
56628885466
655277772323777
2.Find the highest value in each string i.e., 8 n 7
3.i want to replace other than highest no with "-"
string will look like
--------------888------------7777----777---
4. The i want find the middle value of string by los/2 and again replace it by "-"
--------------8---------------7------7----
5. then i want to know the array index of the value with value

What I have tried:

VB
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim s As String = IO.File.ReadAllText("C:\Users\mks\Desktop\Newfolder\test.sp1")
        Dim r As String = Regex.Replace(s.ToString, "----", "-")
        Dim p As String = Regex.Replace(r.ToString, "--", "-")
        Dim t As String = Regex.Replace(p.ToString, "--", "-")
        Dim elements() As String = Regex.Split(t, "-")

        For Each element In elements


        Next
        Dim rp As String
        rp = elements(0)
        Console.WriteLine(rp)


    End Sub
Posted
Updated 10-Oct-17 20:51pm
v2

written in c#, get the logic and do the same in vb, you may find many online code converters to convert c# to vb

using System;
using System.Linq;

namespace CP
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = "----------56628885466----655277772323777---"; 
            string[] parts = input.Split(new char[] { '-' }, StringSplitOptions.None);
            string final = "";
            foreach (string part in parts)
            {
                if (part == "")
                    final += "-";
                else
                {
                    var max = part.Max();
                    string temp = part;
                    foreach (char c in part)
                    {
                        if (c != max)
                            temp = temp.Replace(c, '-');
                    }

                    string temp1 = "";
                    foreach (string item in temp.Split('-'))
                    {
                        if (item == "")
                            temp1 += item;
                        else
                            temp1 += GetMiddle(item);

                    }
                    final += temp1;
                }
            }
            Console.WriteLine(final); //"-----------8------7--7----"

        }

        private static string GetMiddle(  string item)
        {
           var a =  item.Length / 2;
           string temp = "";
           for (int i = 0; i < item.Length; i++)
           {
               if (i == a)
                   temp += item[0];
               else
                   temp += "-";
           }
           return temp;
        }
       


    }
}
 
Share this answer
 
Comments
Member 13307200 11-Oct-17 3:22am    
Thank you very much sir..
I LL check ...
as of now now
i am getting..
----------------------7----
as output
Karthik_Mahalingam 11-Oct-17 3:27am    
ok but the same code with the input iam getting the output as
-----------8------7--7----
Member 13307200 11-Oct-17 3:56am    
Sir in C# its working fine..
I am doing it in vb...
I LL check and update sir...
thank you very much...
Member 13307200 11-Oct-17 5:44am    
Sir plz check out with vb.net..its not showing..
Karthik_Mahalingam 11-Oct-17 6:20am    
sir i am not good at vb.
Here you find the Solution from Karthik converted to VB :
VB
Imports System
Imports System.Linq

Namespace CP
	Class Program
		Private Shared Sub Main(args As String())
			Dim input As String = "----------56628885466----655277772323777---"
			Dim parts As String() = input.Split(New Char() {"-"C}, StringSplitOptions.None)
			Dim final As String = ""
			For Each part As String In parts
				If part = "" Then
					final += "-"
				Else
					Dim max = part.Max()
					Dim temp As String = part
					For Each c As Char In part
						If c <> max Then
							temp = temp.Replace(c, "-"C)
						End If
					Next

					Dim temp1 As String = ""
					For Each item As String In temp.Split("-"C)
						If item = "" Then
							temp1 += item
						Else
							temp1 += GetMiddle(item)

						End If
					Next
					final += temp1
				End If
			Next
			Console.WriteLine(final)
			'"-----------8------7--7----"
		End Sub

		Private Shared Function GetMiddle(item As String) As String
			Dim a = item.Length / 2
			Dim temp As String = ""
			For i As Integer = 0 To item.Length - 1
				If i = a Then
					temp += item(0)
				Else
					temp += "-"
				End If
			Next
			Return temp
		End Function



	End Class
End Namespace
 
Share this answer
 
Comments
Maciej Los 11-Oct-17 5:06am    
5 for effort!
Ralf Meier 11-Oct-17 5:19am    
Thank you Maciej :)
Member 13307200 11-Oct-17 6:31am    
ralf is it working good in vb.net
Ralf Meier 11-Oct-17 6:39am    
Don't thank me - the Solution comes from Karthik ...
But I'm lucky if I could help you ... :)

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