2016-11-14 2 views
-1
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click 
    If TextBox11.Text.Contains("https") Then 
     TextBox11.Text.Replace("https", "http") 
     Debug.WriteLineIf(TextBox11.Text.Contains("http"), "youtube link https replaced with http") 
     If TextBox11.Text.Contains("https") Then 
      ListBox3.Items.Add(TextBox11.Text) 
      Debug.WriteLine("items added to listbox") 
     End If 
    Else 
     Debug.WriteLine("items added to listbox(without repalce)") 
     ListBox3.Items.Add(TextBox11.Text) 
    End If 

End Sub 

그래서 내가 여기에서 시도한 것은 textbox11에서 "https"를 "https"로 대체 한 다음 listbox3에 추가하는 것이 었습니다. 어떤 이유로 든 텍스트를 대체하기도하는데 여기는 약간의 도움이 필요합니다. 알아요, stringbuilder는 이것에 좋지만 사용 방법을 모르겠습니다. 지정된 텍스트를 바꿀 수있는 방법을 찾았습니다. 그러나 전체 문장에서 아닙니다.텍스트 상자의 텍스트를 바꾼 다음 목록 상자에 추가하십시오.

p.s. 내 영어로 미안해.

답변

2

Replace 메서드는 대체 된 텍스트가있는 새 문자열을 반환합니다. 그것은 당신이 전달 동일한 문자열에서 작동하지 않습니다 당신은 내가 (Debug 조항은 가독성을 위해 생략) 당신이 코드를 다음 사용하는 것이 좋습니다

TextBox11.Text = TextBox11.Text.Replace("https", "http") 
+0

니스, 잘 했어, 당신은 2 분 안에 내 문제를 해결했습니다. –

1

교체의 결과를 재 할당 할 필요가 그래서 :.

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click 
    If TextBox11.Text.ToLower.Contains("https") Then 
     TextBox11.Text = TextBox11.Text.ToLower.Replace("https", "http") 
    End If 
    ListBox3.Items.Add(TextBox11.Text.ToLower) 
End Sub 

의 코드가 조금 변경 전파하자

  • ToLower 방법은 대문자 문자를 사용하여 값을 입력하지 않았는지 사용자에게 있습니다.
  • TextBox11.Text = TextBox11.Text.ToLower.Replace("https", "http")은 수정 된 값을 TextBox 개체에 할당하는 올바른 방법입니다.
  • If...End If 구조의 변경을 이해할 수 있습니다. TextBox 값이 수정되었는지 여부와 상관없이 ListBox 개체를 채우려는 것입니다.